惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security @ Cisco Blogs
H
Hacker News: Front Page
P
Privacy International News Feed
N
News and Events Feed by Topic
T
Threatpost
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
K
Kaspersky official blog
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
Security Latest
Security Latest
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
L
Lohrmann on Cybersecurity
Jina AI
Jina AI
P
Proofpoint News Feed
AI
AI
雷峰网
雷峰网
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 叶小钗
Webroot Blog
Webroot Blog
Apple Machine Learning Research
Apple Machine Learning Research
SecWiki News
SecWiki News
罗磊的独立博客
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
S
Security Affairs
Blog — PlanetScale
Blog — PlanetScale
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
月光博客
月光博客
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Securelist
W
WeLiveSecurity
T
Troy Hunt's Blog
A
Arctic Wolf
博客园 - 司徒正美

博客园 - Vincent

Invalid character in a Base-64 string System.ArgumentOutOfRangeException at System.Web.HttpCachePolicy.UtcSetLastModified (DateTime utcDate) Fabulous Adventures In Coding Microsoft will end OEM and shrink-wrapped sales of Windows XP on June 30, 2008 - Vincent My AutoCompleteExtender Windows Live Writer GRI-MindHarbor软件公司 单表继承 (Single Table Inheritance) 写给yzx110的一个实例,仅作参考! 很久没有写blog了. Base64 MD5加密 信用卡是超前消费的一种手段 vs.net2003无法打开*.xsd文件的解决方法 针对MS Project 2003 的开发 Test Your Knowledge of Microsoft Visual Studio .NET page event Microsoft Office InfoPath 2003 Toolkit for Visual Studio .NET 在Code-Behind中操作WebUserControl
reCaptcha 在UpdatePanel 和 ModalPopup中的使用 - Vincent
Vincent · 2010-07-11 · via 博客园 - Vincent

当前支持asp.net最新版本的reCaptcha是1.0.4.0 可以在这里下载.随后在这里申请reCaptha key.

下载后,引用Recaptcha.dll. 然后将如下代码添加到aspx或ascx中:

<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>

UpdatePanel:

aspx code:

<asp:UpdatePanel ID="upComment" runat="server" UpdateMode="conditional">
      <ContentTemplate>
               <asp:TextBox TextMode="MultiLine" runat="server" ID="txtComment" Height="100px" Width="450px" /><br />
              <asp:RequiredFieldValidator ID="rvComment" runat="server" ControlToValidate="txtComment"  ErrorMessage="Comment field is required!" />
   </ContentTemplate>
</asp:UpdatePanel>
<recaptcha:RecaptchaControl ID="recaptcha" Theme="clear" runat="server" PublicKey="your publicKey" PrivateKey="your privateKey" />
<asp:UpdatePanel ID="upButton" runat="server" UpdateMode="Conditional">
         <ContentTemplate>
              <asp:Label ID="lbtRecaptchError" runat="server" ForeColor="Red" />
                <div>
                      <asp:Button ID="btnOk" runat="server" Text="  Ok  " OnClick="btnSaveComment_Click" Visible="true" CausesValidation="true" />
                                           &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click"   CausesValidation="false" Visible="true" />
                </div>
          </ContentTemplate>
</asp:UpdatePanel> 

CS Code:

 protected void btnSaveComment_Click(object sender, EventArgs e) {
if (recaptcha.IsValid) {
//验证通过后在这里可以获得txtComment.Text值.
//..............//然后清空 txtComment.Text = string.Empty;
lbtRecaptchError.Text
= string.Empty;
upComment.Update();
}
else {
//验证失败可以获得reCaptcha返回的信息 lbtRecaptchError.Text = recaptcha.ErrorMessage;
//这里将更新reCaptcha的验证码. ScriptManager.RegisterClientScriptBlock(Page,Page.GetType(), "whatever1","Recaptcha.reload();", true);
upButton.Update();
}

}

protected void btnCancel_Click(object sender, EventArgs e) {
lbtRecaptchError.Text
= string.Empty;
txtComment.Text
= string.Empty;
upButton.Update();
upComment.Update();
}

ModalPopup

aspx Code:

<asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional">
  <ContentTemplate>
      <asp:LinkButton ID="lbtLeaveComment"  runat="server" Text="Leave your comment" OnClientClick="return Recaptcha.reload();" />
          <div id="divComment" runat="server" style="background-color: #ffffff; border-width: 3px; border-style: solid; border-color: Gray; padding: 3px; width: 590px;">
              <table>
                  <tr>
                      <td align="right" style="font-weight: bold" valign="top">
                          Add Comment:
                      </td>
                      <td align="left">
                          <asp:UpdatePanel ID="upInner" runat="server" UpdateMode="conditional">
                              <ContentTemplate>
                                  <asp:TextBox TextMode="MultiLine" runat="server" ID="txtComment" Height="100px" Width="450px" /><br /><asp:RequiredFieldValidator ID="rvComment" runat="server" ControlToValidate="txtComment"  ErrorMessage="Comment field is required!" />
                              </ContentTemplate>
                          </asp:UpdatePanel>
                      </td>
                  </tr>
                  <tr>
                      <td colspan="2" align="center">
                          <recaptcha:RecaptchaControl ID="recaptcha" Theme="clear" runat="server" PublicKey="your publicKey" PrivateKey="your privateKey" />
                          <asp:UpdatePanel ID="upButton" runat="server" UpdateMode="Conditional">
                              <ContentTemplate>
                                  <asp:Label ID="lbtRecaptchError" runat="server" ForeColor="Red" />
                                  <asp:Button ID="btnOk" runat="server" Text="  Ok  " OnClick="btnSaveComment_Click" Visible="true" CausesValidation="true" />
                                  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                                  <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" CausesValidation="false" Visible="true" />
                              </ContentTemplate>
                          </asp:UpdatePanel>
                      </td>
                  </tr>
              </table>
          </div>
    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalBackground"
        PopupControlID="divInner" DropShadow="false" TargetControlID="lbtLeaveComment">
    </asp:ModalPopupExtender>
  </ContentTemplate>
</asp:UpdatePanel>

其中 OnClientClick="return Recaptcha.reload();" 是关键.

CS Code:

   protected void btnSaveComment_Click(object sender, EventArgs e) {
if (recaptcha.IsValid) {
//省略............. txtComment.Text = string.Empty;
lbtRecaptchError.Text
= string.Empty;
Hide();
}
else {
lbtRecaptchError.Text
= recaptcha.ErrorMessage;
ScriptManager.RegisterClientScriptBlock(Page,Page.GetType(),
"whatever1","Recaptcha.reload();", true);
upButton.Update();
}
}
protected void btnCancel_Click(object sender, EventArgs e) {
lbtRecaptchError.Text
= string.Empty;
txtComment.Text
= string.Empty;
upButton.Update();
Hide();
}
private void Hide() {
ModalPopupExtender1.Hide();
upComment.Update();
}