本文转自:http://stackoverflow.com/questions/2083929/dropdownlist-doesnt-postback-after-page-clientvalidate

Update:

I have just found the solution. The following function works (remove the else part):

function confirmSubmit() {
if (Page_ClientValidate("Group1")) {
return window.confirm("Are you sure to submit the form?");
}
}

But I am wondering why it doesn't work when I add the else part.

Question:

I want to have a confirm dialog after user fills in all the data in the form. I set onclientclick="return confirmSubmit()" in the submit button.

 function confirmSubmit() {

     if (Page_ClientValidate("Group1")) {
return window.confirm("Are you sure to submit the form?");
} else { return false;
}
}

If Page_ClientValidate("Group1") returns false, the dropdownlist doesn't cause postback after I first select the item, and the postback only occurs when I select the dropdownlist second time.

What's the problem?

asked Jan 18 '10 at 4:37
Billy

5,473225691
 
1  
Your validation rules are saying the page is invalid and causing the postback to stop...which is what they're supposed to do. Can you post the markup for your validators? One of them in Group1 is saying that it's not in a valid state. – Nick Craver♦ Jan 18 '10 at 4:46
    
I have found the solution. – Billy Jan 18 '10 at 4:56

2 Answers

After Page_ClientValidate is called, the variable Page_BlockSubmit gets set to true, which blocks the autopost back. Page_BlockSubmit was getting reset to false on the second click, for what reasons I still don't fully understand. I'm looking more into this, but I have a solution and I'm under the gun so I'm rolling with it....

Just add below code in the code block which executes if Page is not valid.

Page_BlockSubmit = false;

e.g.

function ValidatePage()
{
flag = true;
if (typeof (Page_ClientValidate) == 'function')
{
Page_ClientValidate();
} if (!Page_IsValid)
{
alert('All the * marked fields are mandatory.');
flag = false;
Page_BlockSubmit = false;
}
else
{
flag = confirm('Are you sure you have filled the form completely? Click OK to confirm or CANCEL to edit this form.');
}
return flag;
}

[转]Dropdownlist doesn't postback after Page_ClientValidate()的更多相关文章

  1. 解决dropdownlist postback 在 iphone UIwebview 失效的问题

    原因: IPhone UIWebView 的 用户代理 User Agent 在ASP.NET 4.0环境下是不识别的:所以ASP.NET提供了一个默认的,低级的不包括javascript的页面版本 ...

  2. "不能在 DropDownList 中选择多个项。"其解决办法及补充

    探讨C#.NET下DropDownList的一个有趣的bug及其解决办法 摘要: 本文就C#.Net 环境下Web开发中经常使用的DropDownList控件的SelectedIndex属性进行了详细 ...

  3. IsPostBack and DropdownList.

    Encounted the issue accident when helping my classmate dealing with his homework assignment,it turns ...

  4. Asp.net中Postback及Callback

    我们知道,在默认的情况下,当我们点击Asp.net Page中的一个服务器Button时(默认其实是Submit Form),会导致Page被Recreated,这个过程我们称之为Postback,它 ...

  5. jQuery UI Autocomplete Combobox 配 ASP.NET DropDownList

    0.引言   1.起因                  一开始使用Autocomplete做了一个自动补全的文本框,如上图.后来因业务需要希望能在这个文本框的边上做个下拉列表按钮,一按就展开所有支持 ...

  6. Understanding The Complete Story of Postback in ASP.NET

    https://docs.microsoft.com/zh-cn/dotnet/api/system.web.ui.page.ispostback?view=netframework-4.7 http ...

  7. Asp.Net 将枚举类型(enum)绑定到ListControl(DropDownList)控件

    在开发过程中一些状态的表示使用到枚举类型,那么如何将枚举类型直接绑定到ListControl(DropDownList)是本次的主题,废话不多说了,直接代码: 首先看工具类代码: /// <su ...

  8. DropDownList 下拉框选择改变,促发事件和防全局刷新(记录)

    代码: <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:Script ...

  9. DropDownList实现可输入可选择

    1.js版本 <div style="z-index: 0; visibility: visible; clip: rect(0px 105px 80px 85px); positio ...

随机推荐

  1. Java基础学习-- 继承 的简单总结

    代码参考:Java基础学习小记--多态 为什么要引入继承? 还是做一个媒体库,里面可以放CD,可以放DVD.如果把CD和DVD做成两个没有联系的类的话,那么在管理这个媒体库的时候,要单独做一个添加CD ...

  2. InstantClick – 快速响应!让你的网站与众不同

    尽管网络带宽不断增加,但网站并没有更快很多.这是因为最大的瓶颈在于页面加载的延迟.InstantClick 是一个很小的 JavaScript 库,大大加速你的网站响应速度. 在访问者点击一个链接之前 ...

  3. emberjs学习二(ember-data和localstorage_adapter)

    emberjs学习二(ember-data和localstorage_adapter) 准备工作 首先我们加入ember-data和ember-localstorage-adapter两个依赖项,使用 ...

  4. 原生JS:Array对象详解

    Array对象 本文参考MDN做的详细整理,方便大家参考[MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/ ...

  5. javascript --- 事件冒泡与事件捕获

    事件冒泡与事件捕获 事件冒泡和事件捕获分别由微软和网景公司提出,这两个概念都是为了解决页面中事件流(事件发生顺序)的问题.考虑下面这段代码,就不写html->head,body之类的代码了,自行 ...

  6. 精通 CSS 选择器

    CSS 选择器除了样式表匹配元素时需要用到,在使用 jQuery 等库的时候也可以利用 CSS 选择器来选择元素,因此作为前端开发需要熟练掌握.下面是一些常用的 CSS 选择器示例. 元素选择器 E, ...

  7. sql server 2014预览版发布

    MSDN发布sql server2014预览版,如下图: SQL Server 2014新特性: 微软SQL Server部门主管Eron Kelly介绍,通过将交易处理放到内存中进行,新的SQL S ...

  8. 怎么样使用yum来安装、卸载jdk

    安装好的CentOS会自带OpenJdk,用命令 java -version ,会有下面的信息: java version "1.6.0"OpenJDK  Runtime Envi ...

  9. 使用 AngularJS 开发一个大规模的单页应用(SPA)

      本文的目标是基于单页面应用程序开发出拥有数百页的内容,包括认证,授权,会话状态等功能,可以支持上千个用户的企业级应用. 下载源代码 介绍 (SPA)这样一个名字里面蕴含着什么呢? 如果你是经典的S ...

  10. 试用 Nexus OSS 3.0 的docker仓库 (二)

    试用 Nexus OSS 3.0 的docker仓库 (一) : http://www.cnblogs.com/wzy5223/p/5410990.html 三. 创建docker私有仓库,docke ...