asp.net Dropdownlist条件回发
我有一个下拉列表,并有一个回发的事件 selectedIndexChanged,我希望能够在用户更改下拉列表中的值时向用户显示一条消息,根据消息的输入,我将决定是否必须回发。
显示的消息将是您确定吗?如果他选择“是”,我将继续回发,如果他说“否”,我将取消回发并分配先前选择的值。
我已经搜索了很多,但无法找到解决方案,我想是否有一个 javascipt 函数可以确定是否需要回发,这可能会有所帮助,我想
谢谢
I have a dropdownlist and have an event selectedIndexChanged which postsback, i want to be able to show a message to the user whenever he changes the value in dropdownlist, based on the input from the message i will decide if i have to postback or not.
The message shown would be are you sure? if he selects yes i would continue with postback, if he says no, i would cancel the postback and assign the previous value as selected.
I have searched alot but cant figure out a solution to this, i think if there is a javascipt function which determines if a postback is required or not that could help i guess
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以非常简单地停止或取消下拉列表的回发。只需在页面加载事件上添加此 JavaScript 即可。
You can stop can cancel postback of dropdownlist very simply.Just add this javascript on page load event.
为了完成此任务,您需要使用带有自定义客户端 Javascript 的 CustomValidator 来控制回发。
您可以阅读 4Guys 上的这篇文章 通过客户端验证器 JavaScript 示例讨论不同的验证器以获得一个想法。
但核心解决方案是使用自定义验证器仅在表单有效时控制回发。
In order to accomplish this task you will need to use a CustomValidator with custom client side Javascript to control the post back.
You can read this article on 4Guys discussing the different validators with a client side validator JavaScript sample to get an idea.
But the core solution would be using a custom validator to control the post back only when the form is valid.