I need t...">

Call ASP.net function / method from onclick div

I have a main onclick div redirect url.

<div onclick="location.href = 'page.aspx';"> 

I need to make some working server part, and not just redirect when this Div is clicked.

How do I call one of my codes for functions from the onclick div? DIV is the parent control inside usercontrol. I believe I can "fix" it using literal control and entering the query string in onclick, but I would use this as a last resort, since I don't want to use the query string.

Are there other ways to catch a DIV click in code that I might have skipped?

+8
source share
1 answer

You may have a button whose display may be "none". Handle the Div click on the client side, and then from there press the "Click" button of this button and process the server side opinion on the Click event of the button.

 <asp:Button runat="server" id="btnHidden" style="display:none" onclick="btnHidden_OnClick" /> <div onclick="javascript:DivClicked(); return true;"></div> <script> function DivClicked() { var btnHidden = $('#<%= btnHidden.ClientID %>'); if(btnHidden != null) { btnHidden.click(); } } </script> 
+18
source share

All Articles