Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi All,

Could somebody please tell me how do i access the master page control in content page through javascript?

I have got some code as follows.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim tb As TextBox = CType(Master.FindControl("txtMaster"), TextBox)
            Dim val As String = tb.ClientID
            Dim script As String = "<script>" & ControlChars.CrLf & "        function PopulateMaster() {" & ControlChars.CrLf & "            document.getElementById('" & val & "').value = 'Via Content Page.;                " & ControlChars.CrLf & "        }" & ControlChars.CrLf & "        PopulateMaster();" & ControlChars.CrLf & "        </script>"
            If (Not Page.ClientScript.IsStartupScriptRegistered("Mast")) Then
                  Page.ClientScript.RegisterStartupScript(Me.GetType(), "Mast", script)
            End If
 
   End Sub



The problem here is I do not want to call the javascript from code behind, I want to call it from aspx page and i want to change the text of a label placed in master page, based on some clicks in client side in content page.

Could somebody help me!!

Best Regards,
Snigdha
Posted

There can be other ways too, but easiest would be:
1. Run the application.
2. Go to the desired page.
3. Do a 'View Source'
4. Find the Master page control name.
5. Use that name in your ASPX javascript.
 
Share this answer
 
Comments
sargamlucy 9-Jul-10 4:53am    
Thanks Sandeep, It worked.
I will suggest you to provide a unique css class to the control, then find the control from content page with document.getElementsByClassName.
https://developer.mozilla.org/en/dom/document.getelementsbyclassname[^]
http://robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900