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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
Google DeepMind News
Google DeepMind News
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Announcements
Recent Announcements
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Y
Y Combinator Blog
B
Blog RSS Feed
人人都是产品经理
人人都是产品经理
MongoDB | Blog
MongoDB | Blog
量子位
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
有赞技术团队
有赞技术团队
Jina AI
Jina AI
GbyAI
GbyAI

博客园 - newr2006

Android adb.exe 开发模试安装 HttpWebRequest 模拟浏览器访问网站 jquery check box Fiddler Post Debug symbol MC 3090 upgrade to symbol MC 3190 ALTER TABLE unable to add host to SCVMM 2008R2 Cannot generate SSPI context ASP.NET代码对页面输出进行清理 - newr2006 - 博客园 提前两天发邮件 线程 Thread 传参数 好的博客 Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. 解决办法 - newr2006 Hashtable(HashSet),ListDictionary,HybridDictionary 和 NameValueCollection Pocket pc 与 Smartphone 开发的区别 XMl 文件属性的读取 USA 的网站终于把中国的名字排上去了. Menu 控件弹出窗口(popupwindow) 删除一些难删除的程序
Page_ClientValidate 用法
newr2006 · 2008-07-11 · via 博客园 - newr2006

JS script

function ConfirmMe()
{
   return confirm("Do you want to proceed?");
}

ASPX

<asp:TextBox id="txtName" runat="server"/>
<asp:Button id="btnSubmit" OnClientClick="return ConfirmMe()" Text="Submit" runat="server"/>

Well, that is pretty straightforward. BUT, it goes weird when you have a validator control (eg. RequiredFieldValidator) that is used to validate the "txtName" textbox server control. For instance,

<asp:TextBox id="txtName" runat="server"/>

<asp:RequiredFieldValidator id="rq1" ControlToValidate="txtName" ErrorMessage="Name cannot be blank" Display="Dynamic" runat="server"/>

<asp:Button id="btnSubmit" OnClientClick="return ConfirmMe()" Text="Submit" runat="server"/>

Whenever you press the button with no textbox value, the client-side confirmation dialog will be invoked first before the validator message is able to show up. This isn't what we expected it to behave. I tried several ways to overcome this problem, including using CLIENT CALLBACK, disabling the CauseValidation, but it failed. Finally, I was able to find a solution by adding JUST ONE line in the JS script.

function ConfirmMe()
{
   if(Page_ClientValidate())
      return confirm('Do you want to proceed?');

   return false;
}