Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegisterStartupScript and MasterPages? 1

Status
Not open for further replies.

NoCoolHandle

Programmer
Apr 10, 2003
2,321
US
Is there any way to do something like what the page.RegisterStartupScript does in a masterpage?

It seems to play ok if you aren't using masterpages, but if you are it fails.. even if I place it in the pageload of the Content Page.

As a workaround (what I needed to do was set a java script variable) I used the following trick
Code:
<input type=hidden id=iptMsg value="<%=getVariableValues%>">
Then I initialazed the variable from the Input control
Code:
    msg   = iptMsg.value;

It seems to do what I need, but it might be nice to know how to use the RegisterStartupScript Method in the future.

I tried both the page.startupscript and the clientscript.startupscript methods and had a resounding failure.


Any thoughts welcome

Rob


 
How did you add it to the Master Page? This seems to work fine for me:
Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Page.ClientScript.RegisterStartupScript(Me.GetType, "myscript", "alert('I fired from the Master Page');", True)
    End Sub


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
It looks like I need to try again. I must have stuck a colon in the wrong place, or mixed up case..

[morning]

Again Thanks..

Rob
 
Seems like you're missing the runat=server attribute for the input tag.

Cheers,

G.

Oxigen - Next generation business solutions
-----------------------------
Components/Tools/Forums/Software/Web Services
 
That isn't the problem (and wouldn't cause an error anyway). The above code that the poster provided was what they used as a workaround (and it was working). They just wanted to know why their original method didn't work.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Wasn't needed with the yellowtags.

i.e. <% =serversidefunction() %> just inserts the value of the function in the location of the tags..

If you wanted to do this from the page load.. then yes you would.
 
Mark,

once again my thanks (and a star)..

Once I crossed to different Browsers I found that my trick didn't work. Your sanity check caused me to try again, and with the same failed result.. (my JavaScript is weak)

What I was doing wrong is that I was trying to build a Java script block without linebreaks.. Than caused the startup script to fail (with very poor error feedback to say why) so... at that point I knew that if a simple script that raised an alert worked, there was something in thwe way I was building the script.

End code had a line crlf at the end of each string and worked like a charm!

Wouldn't have got there without your help@!!!!

Again my thanks


Rob

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top