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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

JRB-Bldr

Programmer
May 17, 2001
3,281
US
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




 
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
 
You can still use your code, just add the attribute ClientIDMode = "Static" to any asp.net control you are referencing in the javascript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top