简体   繁体   中英

Retain anchor after postback in asp.net

I'm using a coda slider like consctuct on one of my pages. Naturally, the anchor ("#currentTab") information is lost after a postback. 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:

  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.

Either execute your postback as an AJAX request, or add some javascript to the form that will send the anchor value to the server

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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