Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按钮刷新不清除文本_C#_Asp.net_Updatepanel - Fatal编程技术网

C# 按钮刷新不清除文本

C# 按钮刷新不清除文本,c#,asp.net,updatepanel,C#,Asp.net,Updatepanel,我正在为我的网站做一个验证码,没有什么新奇的东西,只是为了个人使用。我的问题是,当我点击刷新按钮在验证码框中显示新图像时,它也应该重置验证码文本框 我是这样设置的 protected void btnRefresh_Click(object sender, EventArgs e) { //This is the call that creates a new image FillCaptcha(); // to clear

我正在为我的网站做一个验证码,没有什么新奇的东西,只是为了个人使用。我的问题是,当我点击刷新按钮在验证码框中显示新图像时,它也应该重置验证码文本框

我是这样设置的

   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> `

您应该将
文本框
移动到
更新面板
中。像这样:

<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>

txtCaptcha.Text
在更新面板之外。把它移到里面。你确定
txtCaptcha.Text=String.Empty行被击中了?@VDWWD正在尝试。@克里斯·皮克福德我设置了断点以查看它是否被击中了,以及它是否被击中了。@VDWWD感谢您现在提供的帮助。希望我能给你一些建议。是的,我读过,不明白文本框是怎么布置的。我是ASP.NET新手。有时候真是太挑剔了