我的网站上有一个表单,在填写时应该存储在数据库中。我正在使用存储过程。当我使用代码隐藏调用该过程时,null被存储在数据库中。当我硬编码参数的值时,我发现文本框中的文本没有到达代码隐藏。 aspx代码:
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.
推荐答案我找到了答案。我在页面加载中将所有文本框的文本设置为空。 我以为这会清除文本框。但是现在文本仍然保留在文本框中,即使在提交之后。 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.
您是否有任何特定原因要为按钮添加更新面板?另外,你是否在物理上向表单添加了按钮,或者你在其他地方复制了html代码按钮? 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?
我使用了更新面板因为我使用了reCaptcha。 我自己添加了按钮。 我想出了答案。我在页面加载中将所有文本框的文本设置为空。 我以为这会清除文本框。但现在即使提交后文本仍保留在文本框中。 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.
更多推荐
文本框中的值未达到代码隐藏。
发布评论