Where is Page.RegisterClientScriptBlock Available?

N

Nathan Sokalski

I have used the RegisterClientScriptBlock method in external functions of
mine (ones that are saved in a separate *.vb file), where I use them as
follows:

Public Shared Sub MyFunction(ByVal txtbox As TextBox)
'other code
txtbox.Page.RegisterClientScriptBlock("mykey","myscript")
'other code
End Sub

When I use this external function in my *.aspx.vb files, it does what I want
and expect. However, when I try to use the RegisterClientScriptBlock in my
*.aspx.vb files, it is not included in the list of methods, properties, etc.
when I type 'Page.' Why is Visual Basic not listing this method with the
others while I am writing my code? The *.aspx.vb file inherits
System.Web.UI.Page just like all the *.aspx.vb files. Thanks.
 
M

Mark Rae

When I use this external function in my *.aspx.vb files, it does what I
want and expect. However, when I try to use the RegisterClientScriptBlock
in my *.aspx.vb files, it is not included in the list of methods,
properties, etc. when I type 'Page.'

Is it available when you type 'Me.'?
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

You need a reference to the actual Page object for the page that is
created as a response to the request.

In the example you show, that is accomplished by the fact that the
control that you are passing to the method contains a reference to the
page that it has been added to.

Inheriting the Page class would give you access to the
RegisterClientScriptBlock method, but that doesn't help you a bit. You
need a reference to the page that is being created, not just any Page
object.
 
N

Nathan Sokalski

I realize that I need access to the Page object that is being created, but
shouldn't the keyword Me do that, as Mark Rae mentioned in one of the other
responses?
 
N

Nathan Sokalski

I have done that. I always use a separate code-behind file (each page has a
*.aspx and *.aspx.vb file). I tried creating a new webform, and it did not
act any differently. Is it possible that there is anything in the Web.config
file or somewhere else that could be preventing me from using
RegisterClientScriptBlock? Thanks.
 
T

Teemu Keiski

in VS, check

Tools->Options->Text Editor->Basic->General

and check that "Hide advanced members" is unchecked. If it is checked, VS
will hide some methods from you.
 
N

Nathan Sokalski

THANK YOU! It might have taken me who knows how long to find that, and it is
definitely an important method in some cases. Thanks again!
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Only if the code is inside the page class. If the code is in some other
class, the Me keyword references the instance of that class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top