开发者

span tag onclick to call a code behind method

Hai guys,

How to make a span tag behave exactly like an asp:button (ie) using its onclick method to call a开发者_开发知识库 codebehind method..

<span onclick="MyPageMethod()"></span>

I know linkbuttons can do it for me,but my question is can span tag do it for me?


Having a span tag be clickable is generally a Very Bad Idea. It's bad for UI and it's bad for accessibility because it's not something that a user would expect. You should use anchor tags and buttons if it's clickable.

But to answer your question: Yes, it's definitely possible to do something like this! You just have to mimic what the LinkButton control does.

To get the JavaScript code that does an ASP.NET postback you need to call:

Page.ClientScript.GetPostBackEventReference()

More info is on MSDN.

Then you have to write code on the page that handles the postback and calls MyPageMethod().


Call __dopostback method in javascript.
See followings:
http://urenjoy.blogspot.com/2009/02/add-dynamic-buttons-and-handle-click.html
http://aspalliance.com/895_Understanding_the_JavaScript___doPostBack_Function
http://geekswithblogs.net/mnf/archive/2005/11/04/59081.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜