按钮刷新不清除文本
Button Refresh Not clearing text
我正在为我的网站制作一个验证码,没什么特别的,供个人使用。我的问题是,当我点击刷新按钮在验证码框中显示一个新图像时,它也应该重置验证码文本框。
我是这样设置的
protected void btnRefresh_Click(object sender, EventArgs e)
{
//This is the call that creates a new image
FillCaptcha();
// to clear the text box
txtCaptcha.Text = String.Empty;
}
当我 运行 调试器时,它显示在文本框中输入的值,然后设置为“”。
这是按钮和文本框布局
<asp:TableRow>
<asp:TableCell>
Enter Below Captcha Code :
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtCaptcha" runat="server" Width="200px"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
</asp:TableCell>
<asp:TableCell VerticalAlign="middle">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UP1" runat="server">
<ContentTemplate>
<table>
<tr>
<td style="height: 50px; width:120px; border:solid; border-color:blue; text-align:center;">
<asp:Image ID="imgCaptcha" runat="server" />
</td>
<td valign="middle">
<asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:TableCell>
</asp:TableRow> `
我在 Stack 上搜索了一段时间,每个人似乎都按照我的设置进行设置。我在另一个函数中对 txtCaptcha.Text = String.Empty;
进行了相同的调用,并且工作正常。任何帮助将不胜感激。如果我对某些事情不清楚,请告诉我,我会尽力更好地解释它。
Captcha layout
你应该把你的 TextBox
移到 UpdatePanel
里面。像这样:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UP1" runat="server">
<ContentTemplate>
<table>
<tr>
<td colspan="2">
<asp:TextBox ID="txtCaptcha" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="height: 50px; width:120px; border:solid; border-color:blue; text-align:center;">
<asp:Image ID="imgCaptcha" runat="server" />
</td>
<td valign="middle">
<asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
我正在为我的网站制作一个验证码,没什么特别的,供个人使用。我的问题是,当我点击刷新按钮在验证码框中显示一个新图像时,它也应该重置验证码文本框。
我是这样设置的
protected void btnRefresh_Click(object sender, EventArgs e)
{
//This is the call that creates a new image
FillCaptcha();
// to clear the text box
txtCaptcha.Text = String.Empty;
}
当我 运行 调试器时,它显示在文本框中输入的值,然后设置为“”。
这是按钮和文本框布局
<asp:TableRow>
<asp:TableCell>
Enter Below Captcha Code :
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtCaptcha" runat="server" Width="200px"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
</asp:TableCell>
<asp:TableCell VerticalAlign="middle">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UP1" runat="server">
<ContentTemplate>
<table>
<tr>
<td style="height: 50px; width:120px; border:solid; border-color:blue; text-align:center;">
<asp:Image ID="imgCaptcha" runat="server" />
</td>
<td valign="middle">
<asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:TableCell>
</asp:TableRow> `
我在 Stack 上搜索了一段时间,每个人似乎都按照我的设置进行设置。我在另一个函数中对 txtCaptcha.Text = String.Empty;
进行了相同的调用,并且工作正常。任何帮助将不胜感激。如果我对某些事情不清楚,请告诉我,我会尽力更好地解释它。
Captcha layout
你应该把你的 TextBox
移到 UpdatePanel
里面。像这样:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UP1" runat="server">
<ContentTemplate>
<table>
<tr>
<td colspan="2">
<asp:TextBox ID="txtCaptcha" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="height: 50px; width:120px; border:solid; border-color:blue; text-align:center;">
<asp:Image ID="imgCaptcha" runat="server" />
</td>
<td valign="middle">
<asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>