Click to See Complete Forum and Search --> : Load external script within Page_Load Event


kwilliams
10-09-2006, 11:57 AM
Languages Used: ASP.NET 2.0, VB.NET, XML, XSLT
Development Software: Visual Web Developer 2005 Express Edition, XMLSpy 2006

I'm a complete newbie to ASP.NET and VB.NET, and I've created a dynamic website contains one central page (index.aspx) that loads XML, XSLT, and sometimes VB.NET data into an ASP.NET page using a querystring value (i.e. http://www.mysite.com/index.aspx?page=home). This value is added to the end of a static path to load the page-specific files, like this:
http://www.mysite.com/docs/xml/home.xml
http://www.mysite.com/docs/xslt/home.xsl
http://www.mysite.com/bgscripts/vb/home.vb

But now I need to know how to load an external VB.NET script within a Page_Load Event. I've looked into the "RegisterClientScriptInclude" method, but I've run into issues with adding a reference to this method. I don't know which reference to choose from the list of references, and I continue to receive this error message: Type 'ClientScriptManager' is not defined.

So if anyone can give me some suggestions on how to do this, whether it would include this or another method, that would be great. Thanks for any help.

Cstick
10-09-2006, 11:28 PM
If you are trying to dynamically load .net code to be run on the server, then I'm pretty certain that you're heading down the wrong road with RegisterClientScriptInclude. The key word here is "Client", like javascript or vbscript. This methods is supposed to be used to load a client side script.

Sorry too, I do not know a reliable way to do what you are attempting. I have looked into UserControls ".ascx" as an idea for dynamic forms and such. I had mild success with adding them into pages dynamically. However I didn't spend much time on it, too many projects and deadlines. :(

sirpelidor
10-09-2006, 11:55 PM
you're heading down the wrong road with RegisterClientScriptInclude.

I have looked into UserControls ".ascx" as an idea for dynamic forms and such.


As Cstick said, you can't do it with RegisterClientScriptInclude like php or asp does. If you just wanted to apply MVC to your .net application like jsp/servlets, then you have to implement it through using .ascx usercontrols.

Suppose you have "index.aspx" sitting at the root of your application folder, and you have a sub folder call "components", itself it contain 4 pages to include, page1.ascx, page2.ascx, page3.ascx and default.ascx.

in your index.aspx, you would have a placeholder to hold a control...

<form runat="server">
<asp:placeholder id="myPlaceHolder" runat="server"></asp:placeholder>
</form>


now in your code-behind... you'll have a way read from your httpget and pick the correct ascx file based on the httpget value...


private void Page_Load(object sender, System.EventArgs e){
Control con;
//make sure you are reading stuff from your querystring...
switch ((Request.QueryString.HasKeys()==true?Request.QueryString.GetKey(0).ToString().Trim():Request.QueryS tring.ToString().Trim())){

case "page1":
con = LoadControl ("components/page1.ascx");
break;
case "page2":
con = LoadControl ("components/page2.ascx");
break;
case "page3":
con = LoadControl ("components/page3.ascx");
break;
default:
con= LoadControl("components/default.ascx");
break;
}//end switch

myPlaceHolder.Controls.Add(cont);
}//end page load

kwilliams
10-19-2006, 05:19 PM
Hello sirpelidor and Cstick,

I wanted to thank you both for your replies. It helped me to go in a different, proper, and successful direction with my site.

I'm now working on the code for each form, and that's thanks to you. Have a good one:)