回发 vb.net 上选定的单选按钮列表值出现问题
我在页面上有一个用于配置产品的单选按钮列表。 当页面第一次加载时,会显示第一个选项列表。 您选择其中一个,然后单击“下一步”按钮,页面会回发并显示步骤 2 的新单选按钮列表。现在,如果我单击“上一步”按钮,我可以轻松获取要显示的上一个选项列表但由于某种原因我无法选择其中一个单选按钮。 我可以轻松地找回我需要的价值。 在制作单选按钮列表之后,我有一个步骤只是说 radiobuttonlist.selected =“somevalue”,具体取决于用户第一次完成第一步时选择的任何内容。
当我调试时,我看到该值是正确的并且正在应用。 但当页面显示时,单选按钮未被选中。
我注意到,当我在调试时单击“上一页”按钮时,会发生以下步骤:
page.load 处理程序运行,并且 if not page.ispostback 块内的代码不运行,这是正确的。 然后我刚刚单击的按钮的句柄就会运行。 但之后 page.load 处理程序再次运行,但这一次 if not page.ispostback 块中的代码确实运行...
这正常吗? 让 page.onload 块像回发时那样运行两次? 我认为这可能与我的价值没有得到应用有关。
I have a radio button list on a page that is used to configure products. when the page loads the first time the first list of options is displayed. you select one of them then click a "Next Step" button and the page posts back and shows a new radio button list for step 2. Now if i click a "Previous Step" button i can easily get the previous list of options to display but i can not for some reason get one of the radio buttons to be selected. I can easily bring back the value i need. right after making the radio button list i have a step that just says radiobuttonlist.selected = "somevalue" depending on whatever the user chose when they completed the first step the first time.
when i debug i see that the value is correct and is being applied. but then when the page is displayed the radiobutton is not selected.
I have noticed that when i click my "Previous" button while debugging the folowing steps occur.:
the page.load handler runs and the code inside my if not page.ispostback block does NOT run, which is correct.
then the handles for the button i just clicked gets run.
but then after that the page.load handler runs again but this time the code in the if not page.ispostback block DOES run...
is that normal? for the page.onload block to run twice like that on a postback? i think it may have something to do with why my value is not being applied.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
尝试这样做
Try to do this
我确实有一个我正在使用的response.redirect,但我删除了它。 我想我可以做一次彻底的检查,以确保我在任何地方都没有另一个。 我也会尝试 autoeventwireup 属性。
I DID have a response.redirect i was using but i removed it. I suppose i can do a thorough check to make sure i didnt have another one anywhere. I will try the autoeventwireup property as well.
好吧,看起来 autoevenwriteup 属性在我开始之前就已经设置为 false。 所以我不认为是这样。
我没有看到任何其他重定向发生......我想搜索仍在继续。
alright well it looks like the autoevenwriteup property was already set to false before i even started. so i don't think that was it.
I didn't see any other redirects happening anywhere... i guess the search continues.
您是否尝试过在页面的预渲染阶段而不是 Page_Load 期间设置所选值?
Have you tried setting the selected value during the page's pre-render phase instead of Page_Load?
听起来您正在导致重定向发生。 您不是偶然执行 Response.Redirect 以便“返回”原始页面吗? 这会导致您描述的功能。 您将首先从上一个按钮获取回发以离开页面,然后当页面重新加载时您将获得一个新的请求(IsPostback = false)。
It sounds like you are causing a redirect to happen. You aren't by chance doing a Response.Redirect in order to "get back" to the original page? This would cause the functionality you describe. You would first get the Postback from the Previous button to leave the page, and then you would get a fresh Request (IsPostback = false) as the page reloads.
尝试在页面中设置
AutoEventWireup = False
。Try setting
AutoEventWireup = False
in the page.可能的原因之一,也是我最近遇到的问题是,radiobuttonlist 根据值而不是 ID 来区分项目,因此如果存在重复值,就会出现此问题。
下面的链接提供了详细的解释。
RadioButtonList 所选项目不粘在上面回发
One of the probable reason, and the one which I faced recently is because of the fact that radiobuttonlist distinguish the items on the basis of value and not ID, thus if duplicate values exist, this issue will be observed.
Below link provide the detailed explanation.
RadioButtonList selected item does not stick on postback
我遇到了同样的问题,就像 Thunder3 提到的那样,我重定向回页面,并调用 Page_Load 上的方法来设置 RadioButtonList 选定值。 但所选值未应用于RadioButtonList。
我通过调用 Page_Init 上的方法解决了这个问题。
I had the same issue, like what Thunder3 mentioned, I did a redirect back to the page, and was calling a method on Page_Load, to set the RadioButtonList selected value. But the selected value was not applied to the RadioButtonList.
I solved the issue by calling the method on Page_Init instead.