How to access the content page control from master page click event ?


masterpage

Hi

One time, i was asked this question in one of my interview “How to access the content page control from master page click event ?”

here is the exact answer, we can access the content page from master page click event using Findcontrol like this

protected void btnClick_Click(object sender, EventArgs e)
{
TextBox txtbox1 = (TextBox)ContentPlaceHolder1.FindControl(“Textbox1”);
if (txtbox1 != null)
{
txtbox1.Text = “Content Textbox”;
}
}

Note: I have written this code in master page on btnclick event

Advertisement

How to design master page with proper CSS ?


masterpage
Hi

I have seen so many person used to design the master page in asp.net without writting CSS just like drag, drop and so many hardcoded alignment with in that master page. But it is not a good practice ane even though html page will look so dirty.

For design any master, you can write proper external css class which will be applicable in all the page like this

Step1: Write this in external CSS file

html
{
font-family:Tahoma;
font-size:14px;
font-style:normal;
background-color:Silver;
}
.Content
{
margin:auto;
width:700px;
background-color:white;
border:Solid 1px black;
}

Note: here whatever css you will write in html portion that will be applicable to all the pages where you will call css file reference.

Step 2: drag and drop the css reference in master header portion
Step3 : Call the CSS class in master in like

<form id=”form1″ runat=”server”>
<div class=”Content”>
<div>This is the header part</div>
<asp:Button ID=”btnClick” runat=”server” Text=”Click Here”
onclick=”btnClick_Click” />
<asp:ContentPlaceHolder id=”ContentPlaceHolder1″ runat=”server”>

</asp:ContentPlaceHolder>
<div>This is the footer part</div>
</div>
</form>