简体   繁体   English

在asp.net中回发后保留锚点

[英]Retain anchor after postback in asp.net

I'm using a coda slider like consctuct on one of my pages. 我在其中一页上使用像consctuct这样的滑块 Naturally, the anchor ("#currentTab") information is lost after a postback. 自然,回发后锚(“ #currentTab”)信息会丢失。 This is annoying because when you press a button on a certain tab, you always end up on the first tab after the postback. 这很烦人,因为当您按下某个选项卡上的按钮时,您总会在回发之后最终出现在第一个选项卡上。

What is the best way of letting this information survive a postback? 让这些信息保留回发的最佳方法是什么?

尝试这是您的page_load事件

Me.Form.Attributes("onsubmit") = "this.action+=top.location.hash;"

I'm not doing in ASP, but as a general solution attempt this might work for you too: 我不在ASP中进行操作,但是作为一种一般的解决方案尝试,这也可能对您有用:

  1. create a hidden field within the form that you send 在您发送的表单内创建一个隐藏字段
  2. on tab change, fill in the value for this selected tab (if there are no values for identifying the tabs, create them) 在更改标签时,填写此所选标签的值(如果没有用于标识这些标签的值,请创建它们)
  3. when rendering the page after submit, create a piece of javascript on the fly, which switches the tab on DOM:ready. 提交后呈现页面时,请动态创建一段JavaScript,以切换DOM:ready选项卡。

Either execute your postback as an AJAX request, or add some javascript to the form that will send the anchor value to the server 作为AJAX请求执行回发,或将一些javascript添加到将锚定值发送到服务器的表单中

Rough example 粗略的例子

<form onsubmit="this.anchor.value=top.location.hash">
    <input name="anchor" type="hidden" value="">
    <!-- rest of form -->
</form>

Then you'll need a convention to return it to the client and perform the appropriate action. 然后,您将需要一个约定以将其返回给客户端并执行适当的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM