Reputation: 35268
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?
Upvotes: 2
Views: 5903
Reputation: 6122
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
Link
Upvotes: 1
Reputation: 25704
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()
.
Upvotes: 5