0

I have a master page with a TextBox control on it. In the code behind of the said master page, I can't access the TextBox control and assign a text to it. Below is the source code of the master page:

<asp:TextBox CssClass="txt" ID="txtSN" runat="server" ></asp:TextBox>

but in them master page code behind, i can't access to this TextBox Id getting error

txtSn.text=""

why?

aram
  • 5
  • 6
  • Where in the code behind is txtSn.text="". Can you paste the method you have this code in? Is this in Page_Load? – Aaron Sep 19 '18 at 19:42
  • i write **txtSn.text="";** in master page_load but getting error – aram Sep 19 '18 at 20:28

1 Answers1

0

Check if the property of the text box is defined in the designer class of your master page (yourmasterpagename.master.designer.cs). If not, you need to define to access it in the code behind.

    /// <summary>
    /// txtSN control.
    /// </summary>
    /// <remarks>
    /// Auto-generated field.
    /// To modify move field declaration from designer file to code-behind file.
    /// </remarks>
    protected global::System.Web.UI.WebControls.TextBox txtSN;
Rakesh Sajja
  • 148
  • 9
  • The mater page designer(yourmasterpagename.master.designer.cs) is empty, how can i rebuild it? – aram Sep 19 '18 at 20:33
  • this thread may help you finding why properties are not being created in your code-behind https://stackoverflow.com/questions/6508252/designer-cs-not-updating-when-new-controls-added-to-aspx – Rakesh Sajja Sep 19 '18 at 21:25