Jump to content
kwilliams

RegisterClientScriptInclude Method

Recommended Posts

I'm a newbie to ASP.NET and VB.NET, and I'm trying to develop a way to include an external script file to a central ASP.NET page. After doing some research, I found information on the ClientScriptManager.RegisterClientScriptInclude Method at http://msdn2.microsoft.com/en-us/library/2552td66.aspx.So this is what I developed for my page:

<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" AspCompat="true" Debug="true" %><%@ import Namespace="System.Data" %><%@ import Namespace="System" %><%@ import Namespace="System.IO" %><%@ import Namespace="System.Xml" %><%@ import Namespace="System.Text.RegularExpressions" %><%@ import Namespace="System.Web.UI" %>Sub Page_Load(sender As Object, e As EventArgs)Dim page_path = page_qs 'Querystring variable unique to each pageDim vbkey As String = page_pathDim vbpath As String = "http://SERVERNAME/DIRECTORY/bgscripts/vb/vbdoc.vb"'Define the name, type and url of the client script on the page.		Dim csname As String = vbkey		Dim csurl As String = vbpath		Dim cstype As Type = Me.GetType()		' Get a ClientScriptManager reference from the Page class.		Dim cs As ClientScriptManager = Page.ClientScript		' Check to see if the include script is already registered.		If (Not cs.IsClientScriptIncludeRegistered(cstype, vbkey)) Then			cs.RegisterClientScriptInclude(cstype, vbkey, ResolveClientUrl(vbpath_new))		End IfEnd Sub

But I'm receving this error message:Compiler Error Message: BC30002: Type 'ClientScriptManager' is not defined.I made sure to register the namespace at the top of the page (<%@ import Namespace="System.Web.UI" %>), but I'm still getting the same error. If anyone can help me to figure out what I'm doing wrong, that would be great. Thanks.

Share this post


Link to post
Share on other sites
did you add the reference in VS (or VWD)senu1.jpg
Hi aspnetguy,Sorry that I didn't get back to your question sooner. This forum isn't emailing me even thought I've subscribed to the thread. I'm developing the site using Web Matrix, and I'm not sure how I would add a reference with that...or whether or not I need to. If you could give me more clarification on this, that would be great. Thanks.

Share this post


Link to post
Share on other sites

My first suggestion is, stop using Web Matrix...it is outdated and wasn't that good to begin with.Install .net framework 2.0 and download Visual Web Developer Express, it is free fromt he microsoft site. It is much better than Web Matrix.I don't use web matrix so I do not know how to add the reference either.

Share this post


Link to post
Share on other sites
My first suggestion is, stop using Web Matrix...it is outdated and wasn't that good to begin with.Install .net framework 2.0 and download Visual Web Developer Express, it is free fromt he microsoft site. It is much better than Web Matrix.I don't use web matrix so I do not know how to add the reference either.
I've been thinking of switching to VSE for a bit, so I appreciate your advice. I'll let you know how it goes. Thanks again.

Share this post


Link to post
Share on other sites
My first suggestion is, stop using Web Matrix...it is outdated and wasn't that good to begin with.Install .net framework 2.0 and download Visual Web Developer Express, it is free fromt he microsoft site. It is much better than Web Matrix.I don't use web matrix so I do not know how to add the reference either.
Well, I've installed Visual Web Developer 2005 Express Edition, and I really like it so far. Thanks for the suggestion.
did you add the reference in VS (or VWD)
I see how to add a reference to my site, but I don't know which reference to choose. There are two lists: .NET and COM. I've looked for "Client Script Manager" and "Register Client Script Include", but neither of them are on the lists. Could you help to point me in the right direction?

Share this post


Link to post
Share on other sites
I see how to add a reference to my site, but I don't know which reference to choose. There are two lists: .NET and COM. I've looked for "Client Script Manager" and "Register Client Script Include", but neither of them are on the lists. Could you help to point me in the right direction?
It's .NET. The file you are looking for is System.Web.dll.

Share this post


Link to post
Share on other sites
It's .NET. The file you are looking for is System.Web.dll.
I looked in the list of References in VWD2k5 by going to Website > Add Reference > .NET, but I did not find a file called System.Web.dll. Am I looking in the wrong place?

Share this post


Link to post
Share on other sites

Are you certain that you are using .NET 2.0? I don't know about Visual Web Developer, but in Visual Studio, when I create a new Web Site, most, if not all, of the System DLLs are referenced automatically and don't show up in my bin directory.The Page class is in System.Web.UI, and all of the web controls (like <asp:Button />) are in System.Web.UI.WebControls. If you are able to access those classes then you have System.Web referenced correctly. Therefore, if you have System.Web referenced correctly, then you should be able to access ClientScriptManager unless you are not using 2.0.

Share this post


Link to post
Share on other sites
I don;t think you have to manually add a refrence to System.Web...it should be done for you whne you start a new project.Just make sure you have C#
using System.Web;

At the top of your code, if using code behind.

These are all of the namespaces I have referenced at the top of my page:
<%@ import Namespace="System.Data" %><%@ import Namespace="System" %><%@ import Namespace="System.IO" %><%@ import Namespace="System.Xml" %><%@ import Namespace="System.Text.RegularExpressions" %><%@ import Namespace="System.Web.UI" %>

...so I should be covered, correct? But I still receive the same error message when attempting to call that method.

Share this post


Link to post
Share on other sites

I don;t think you have to manually add a refrence to System.Web...it should be done for you whne you start a new project.Just make sure you have C#

using System.Web;

At the top of your code, if using code behind.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...