文本框中的值未达到代码隐藏。

编程入门 行业动态 更新时间:2024-10-28 00:28:11
本文介绍了文本框中的值未达到代码隐藏。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的网站上有一个表单,在填写时应该存储在数据库中。我正在使用存储过程。当我使用代码隐藏调用该过程时,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.

更多推荐

文本框中的值未达到代码隐藏。

本文发布于:2023-11-09 09:12:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571997.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:框中   文本   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!