I have a form in my website, which, on being filled is supposed to be stored in a database. I'm using a stored procedure for this. When i called the procedure using the code-behind, null was getting stored in the database. When I hard-coded the values of the parameters, I found that the text from the text-box is not reaching the code-behind.
aspx code:
<table>
<tr>
<td class="auto-style2">
<asp:Label runat="server" >Name <span class="req">*</span></asp:Label>
</td>
<td class="auto-style1">
<asp:TextBox ID="tb_name" runat="server" CssClass="form_tb"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" Text="Name is mandatory" ValidationGroup="1" Font-Italic="true" Font-Size="10" ForeColor="Red" ControlToValidate="tb_name">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label runat="server" >E-mail <span class="req">*</span></asp:Label>
</td>
<td class="auto-style1">
<asp:TextBox runat="server" ID="tb_mail" CssClass="form_tb"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tb_mail" Font-Italic="true" Text="Specify valid email address"
ValidationGroup="1" Font-Size="10" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ForeColor="Red" ValidationGroup="1" Font-Italic="true" Text="*Invalid Email Address "
ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="tb_mail" Font-Size="10">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label runat="server">Contact Number <span class="req">*</span></asp:Label>
</td>
<td class="auto-style1">
<asp:TextBox runat="server" ID="tb_num" CssClass="form_tb" MaxLength="10"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv_phone" runat="server" ControlToValidate="tb_num" Font-Italic="true" Text="Specify valid email address"
ValidationGroup="1" Font-Size="10" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<asp:RegularExpressionValidator ID="rev_num" runat="server" ValidationGroup="1" ControlToValidate="tb_num" ForeColor="Red" Font-Italic="true" Font-Size="10"
ValidationExpression="[0-9]{10}">*Invalid Number</asp:RegularExpressionValidator>
</td>
</tr>
</table>
My code-behind for storing the values:
name.Value = tb_name.Text;
email.Value = "hgd@hjf.jf";
phone.Value = "654789076";
The value of name isn't being passed.
connect = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
cmnd = new SqlCommand("submit_form", connect);
cmnd.CommandType = CommandType.StoredProcedure;
cmnd.Parameters.Add(name);
cmnd.Parameters.Add(email);
cmnd.Parameters.Add(phone);
try
{
connect.Open();
cmnd.ExecuteNonQuery();
}
finally
{
if (connect != null)
connect.Close();
}
Could it be because i have an update panel around the submit button?
<div id="btn_holder">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="submit_btn" runat="server" CssClass="submit" Text="Volunteer" ValidationGroup="1" CausesValidation="true" OnClick="btn_submitClick" />
<asp:Button ID="reset_btn" runat="server" CssClass="submit" Text="Reset" OnClick="resetClick" />
<br /><br />
<asp:Label runat="server" ID="lblRes" Font-Size="12" Font-Italic="true"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Kindly help me out.