ASP.NET 中下拉列表的回发和提交按钮的回发之间的区别
我对 ASP.NET 和 ASP.NET 比较陌生。 C# 我正在创建一个基本表格,其中包含学生姓名、课程下拉列表和学期编号下拉列表。我正在使用回发来填充学期号下拉列表。我将通过表单获取的数据显示为标签。我正在使用 IsPostBack 用数据填充标签
我的问题是,当我更改程序时,它会触发回发以填充学期下拉列表,并且由于我使用该事件来显示数据,因此我无法真正选择学期号。
如何区分提交按钮回发和下拉回发?
谢谢!!!
I am relatively new to ASP.NET & C#
I am creating a basic form with student name, program dropdown and semester number dropdown. I am using postback to populate semester number dropdown list. I am showing the data i acquired through the form into labels. I am using IsPostBack to populate the labels with data
My problem is that when I change program, it fires the postback to populate semester dropdown and since I am using that event to display data, I cant really select semester number.
How can I differentiate between submit button postback and dropdown postback?
Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是在加载事件处理程序内部进行编码或使用 isPostBack。只需使用按钮事件处理程序。您可以通过双击设计视图中的按钮来完成此操作。
然而,更好的方法是使用 .Net Ajax 更新面板和脚本管理器,它使用起来非常简单。
下面是使用脚本管理器和更新面板的简单示例,您可以将其用于下拉列表,这样您就不必为此进行回发。所以回发应该只针对按钮。
您可以使用下拉列表来代替上面代码中的文本框。
Instead of coding inside the load event handler or using isPostBack. Just use buttons event handler. You can do that by double clicking on button in design view.
However better way of doing this altogether is use .Net Ajax Update Panel with script manager which is very simple to use.
Below is the simple example of using script manger and update panel, you can use it for drop down list so you don't have to postback for that. So postback should be only for button.
Instead of textbox in above code you can have dropdown list.