INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

StartupScript (javascript) No Longer Working in Web Form from Master Page

StartupScript (javascript) No Longer Working in Web Form from Master Page

StartupScript (javascript) No Longer Working in Web Form from Master Page

(OP)
I had an ASP.Net web page that was working just fine.

It was successfully executing the Javascript Startupscript that was Registered in my VB.Net Page_Load code with:
ScriptManager.RegisterStartupScript(Me.Page, Page.GetType, "ChangeIconStartUpJavaScript", "startUpScript()", True)

Now, with a re-design, I have changed the same page to now use a Master Page.

I was told to put the javascript code into to the new Page source as follows:

CODE -->

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
  function startUpScript() {
     // -- some javascript code here ---
   }

   function chkFileSelect() (
      // --- some other javascript code here ---
   )
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <%-- Other page code (non-javascript) here --%>
</asp:Content> 

But now NONE of the javascript code works at all. Neither the function startUpScript nor the other function(s).
The non-javascript code works just fine, but the previously working javascript code now no longer works.

What am I doing wrong?

Any advice/suggestions you can offer would be greatly appreciated.

Thanks,
JRB-Bldr




RE: StartupScript (javascript) No Longer Working in Web Form from Master Page

(OP)
OK, I found my own answer by looking at the Page's Source Code.

Apparently when the Master Page renders the desired page's content, it appends a prefix to the Content area Object ID's.

Something like: "ContentPlaceHolder1_" + <original Object ID>

So a getElementByID(objName) would never work since the objName was now: "ContentPlaceHolder1_" + objName

Good Luck,
JRB-Bldr

RE: StartupScript (javascript) No Longer Working in Web Form from Master Page

You can still use your code, just add the attribute ClientIDMode = "Static" to any asp.net control you are referencing in the javascript.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close