最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using doPostBack Function in asp.net - Stack Overflow

programmeradmin2浏览0评论

i want to use doPostBack function in my link.When user clicks it,it wont redirect to another page and page will be postback.I am using this code but it doesnt function.Where do i miss?

< a id="Sample" href="javascript:__doPostBack('__PAGE','');">



 function __doPostBack(eventTarget, eventArgument)

  {
           var theform = document.ctrl2

           theform.__EVENTTARGET.value = eventTarget

           theform.__EVENTARGUMENT.value = eventArgument

           theform.submit()
       }

i want to use doPostBack function in my link.When user clicks it,it wont redirect to another page and page will be postback.I am using this code but it doesnt function.Where do i miss?

< a id="Sample" href="javascript:__doPostBack('__PAGE','');">



 function __doPostBack(eventTarget, eventArgument)

  {
           var theform = document.ctrl2

           theform.__EVENTTARGET.value = eventTarget

           theform.__EVENTARGUMENT.value = eventArgument

           theform.submit()
       }
Share Improve this question edited May 8, 2011 at 17:38 santosh singh 28.7k27 gold badges86 silver badges132 bronze badges asked Feb 4, 2009 at 13:30 cemcem
Add a ment  | 

4 Answers 4

Reset to default 1

Try this :

System.Web.UI.HtmlControls.HtmlAnchor myAnchor = new System.Web.UI.HtmlControls.HtmlAnchor();
string postbackRef = Page.GetPostBackEventReference(myAnchor);
myAnchor.HRef = postbackRef;

__doPostBack is an auto-generated function that ensures that the page posts-back to the server to maintain page state. It's not meant to be used for redirection...

You could either use window.location.href="yourpage.aspx" on javascript or Response.Redirect("yourpage.aspx") at server side on the page you are doing the postback.

Why would you want to cause a postback manually? If your information is out of date you can consider an AJAX Timer.

ok but i am using link in my datagrid and when user clicks the link,i want to postback only datagrid content(So the link will change datagrid content and it is not a column.it is a simple text like wikipedia's.The link is created in Run Time by this code,I am using UpdatePanels).

str = regex.Replace(str, "(look: < a href=""javascript:" & Page.GetPostBackEventReference(Me) & ">< font color=""#CC0000"">$1 < /a> )")

If i use,window.location.href,it will postback all page.My target is to postback only datagrid(Ofcourse by taking Link's text as output too).I dont use Frames,and link is not a button.How can i do it?

发布评论

评论列表(0)

  1. 暂无评论