2017-01-12 64 views
0

我正在爲我的網站做一個驗證碼,沒有什麼特別的和個人使用。我的問題是,當我點擊刷新按鈕在驗證碼框中顯示一個新圖像時,它也應該重置驗證碼文本框。按鈕刷新不清除文本

我設置它像這樣

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

伊夫搜索和每個人似乎都將其設置爲我擁有它。我在另一個函數中調用了txtCaptcha.Text = String.Empty;,它工作正常。任何幫助將不勝感激。如果我對事物不清楚,請讓我知道並且盡我所能來更好地解釋它。

Captcha layout

+3

'txtCaptcha.Text'是在UpdatePanel外面。把它移進去。 – VDWWD

+0

你確定'txtCaptcha.Text = String.Empty;'行被擊中? –

+0

@VDWWD現在嘗試。 – poohbear

回答

1

你應該將你的TextBoxUpdatePanel。像這樣:

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

閱讀Introduction to the UpdatePanel Control

+0

雅我讀過,並不明白如何佈局文本框。我是ASP.NET新手。它的瘋狂如何挑剔/棘手有時 – poohbear

+0

這個作品太棒了!謝謝! – poohbear