当用户控件回发时,单选按钮不保留选择
当页面部分回发时,我遇到一些问题。我有一些单选按钮,基于这些按钮我通过 javascript 制作 tr display="" 和 display="none" 。之后我添加行网格视图。 gridview 包含 empltyTemplate 和页脚以添加新行。但是,当我在网格视图中添加行时,用户控件将被回发,因此所有 tr 都变为 displa="none",这是加载页面时的默认值。我试图将 gridview 保留在更新面板中,但它不起作用。我的控件的层次结构如下。
Level-1-母版页--->Level-2-母版页--->Level 3-.aspx页面--->Level 4-用户控制--->Level-5-多个手风琴- ->Level-6:每个手风琴中有 1 个用户控件。
代码太长,无法在此处过去。我尝试将更新面板保留在用户控件(6 级)内,但它不起作用。经过一番谷歌搜索后,我发现如果更新窗格位于 accrdian 内部,则更新窗格不起作用。因此,我尝试将所有 accrdian 保留在更新面板内,但在这种情况下,.aspx 页面不会回发,但放置在 accrodian 内的所有用户控件都会回发,因此选择设置为默认加载时的状态。
我希望在回发最后一级用户控件时保留所有选择。
这种情况很难理解,但这就是事情的本质..如何解决我的问题?
I am facing some problems when page is posted back partially. I have some radio buttons based on which I am making tr display="" and display="none" by javascript. After that I am adding rows gridview. The gridview contains empltyTemplate and footer to add new rows. But when I add row in grid view, the user control is posted back and hence all the tr becomes displa="none" which is default when page is loaded. I tried to keep gridview in update panel but it not working. Hierarchy of my controls is as below.
Level-1-Master page--->Level-2-master page--->Level 3-.aspx page--->Level 4-user control--->Level-5 -multiple accordians-->Level-6: 1 user control in each accordian..
code is too long to past here.. I tried to keep update panel inside user control(Level 6) but it was not working. After some googling I found that update pane not works if it is inside accrdian. So I tried to keep all accrdian inside update panel but in that case .aspx page is not posted back but all user controls placed inside accrodian are posted back so the selection is set as they are on default load.
I want all selection to retain when the last level user control is posted back.
The situation is quite complex to understand but this is what the things are..How to solve my problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JavaScript 对 DOM 所做的更改不会跨 PostBack 保留;服务器不知道你做了什么,因此无法跟踪它。
为了解决这个问题,您要么需要通过回调或 Ajax 调用在服务器端更新 JS 代码的状态,要么让它更新表单中反映标签状态的隐藏输入字段,并让服务器查看那里并相应地更新呈现的 HTML。
Changes made to the DOM from JavaScript are not retained cross-PostBack; the server has no idea what you've done, and therefore has no way to track it.
To solve this, you either need to have your JS code update state on the server side with a Callback or Ajax call -- or perhaps have it update a hidden input field in the form that reflects the state of your tags, and have the server look there and update the rendered HTML accordingly.