Search code examples
asp.netvariablesinputtextboxmaster-pages

Pass TextBox input to variable in ContentPlaceHolder


I can easily pass the textbox input to a variable in an HTML form, but things don't work when using a master page and ContentPlaceHolder.

My Master page is "Site.Master" My sister page is "Page1.aspx"

In it I have asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" Runat="Server", with textBox1.

How to get that input ?

  protected void Button1_Click(object sender, EventArgs e)
{

        string MyContent = TextBox1.Text;
}

This action returns the original text of TextBox1 but not what the user input.


Solution

  • Ahh, of course... I forgot the "if (!Page.IsPostBack)" in Page_Load.