skip to Main Content

I’m trying to get value from input in code behind the problem is value always return empty "" when im using master page but its working fine without master page

html

<asp:UpdatePanel ID="UpdatePanel3" runat="server">
    <ContentTemplate>
        <form action="#" method="post" >
            <input type="text" class="form-control" runat="server" id="email" placeholder="email"  />
        </form>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="btnRegister" />
    </Triggers>
</asp:UpdatePanel>

code behind

protected void btnRegister_Click(object sender, EventArgs e)
{
    string email = email.Value; //retun empty " "
}

2

Answers


  1. you have to use

    <div>
       <form action="#" method="post" >
          
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
      <asp:UpdatePanel ID="UpdatePanel3" runat="server">
     ...
     <asp:TextBox ID="txtEmail" runat="server" CssClass="form-control"</asp:TextBox>
    ....
        </form>
    

    and get value

    var email = txtEmail.Text;
    
    Login or Signup to reply.
  2. i just removed other

     <form action="#" method="post" > 
    

    from MasterPage and its working fine now

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search