Hi
As an example..
I am having a button in master page..
<div> <asp:Button ID="Button25" runat="server" Text="Master Button" /></div>
Now in the content page I am having a script and a button
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<script type="text/javascript" language="javascript">
function showMasterPageControlID(ctrlId){
alert(document.getElementById(ctrlId).id);
}
</script>
<asp:Button ID="Button1" runat="server" Text="Button" />
</asp:Content>
Now I assign the script to the button click event from the code behind as follows
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "showMasterPageControlID('" + this.Master.FindControl("Button25").ClientID + "')");
}
This works..
But if you want to access the master control at page_load event then you may need to inject the script as follows..
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "Script1", "<script type='text/javascript'>document.getElementById('" + this.Master.FindControl("Button25").ClientID + "').value='Master Button Modified';</script>");
}
For setting multiple controls in that way use a string builder to create your script text and get the text from stringbuilder's toString method.
Use the
ClientID
property instead of using the way you identify the controls. Because that id change easily when the html tree hierarchy alters.
Hope this helps