Home > Mobile >  c# button click input value return empty
c# button click input value return empty

Time:12-31

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"  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 " "
}

CodePudding user response:

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;

CodePudding user response:

i just removed other

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

from MasterPage and its working fine now

  • Related