Click here to Skip to main content
15,889,761 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
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:

ASP.NET
 <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:

C#
name.Value = tb_name.Text;
        email.Value = "hgd@hjf.jf";
        phone.Value = "654789076";


The value of name isn't being passed.

C#
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?

ASP.NET
<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.
Posted

I figured out the answer. I was setting the text of all text boxes as empty in page load.
I thought that would clear the textboxes. But now the text remains in the textboxes even after submit.
 
Share this answer
 
Is there any specific reason that you put update panel for the button? Also, did you add the button physically to the form or you copied the html code for button somewhere else?
 
Share this answer
 
Comments
Kruti Joshi 24-Jul-14 13:49pm    
I used the update panel because I have used a reCaptcha.
And I added the button myself.
I used the update panel because I have used a reCaptcha.
And I added the button myself.

I figured out the answer. I was setting the text of all text boxes as empty in page load.
I thought that would clear the textboxes. But now the text remains in the textboxes even after submit.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900