Asp image click click using jQuery Mobile

I am working on a site in VB.NET and JQM - and everything is going fine.

Now I am trying to include a standard image button using a tag, for example:

<asp:ImageButton ID="btnYear" runat="server" ImageUrl="~/images/buttons/year_btn.gif" /> 

and in the VB file behind the file there is a click event similar to the following:

 Private Sub btnYear_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles btnYear.Click Session("TimeFrame") = "YEAR" *do other code* End Sub 

When I click the "Image" button and trace the code - all the code in the page events in the code behind the fire file (page load, page prerender, etc.), but the click event for the image button never fires.

If I replaced the Image button with the standard asp: Button and did the same - then the click event in the code behind the fires is just fine! Is it not possible to use ASP ImageButton on a JQM page and hold the click event in the VB code behind the file?

EDIT Well, we are grateful for the answer, but it brings a new script (problem) with my page to the light, also concerning these ImageButtons.

I have ImageButton controls contained in a user control. My page is one ASPX file with several <div data-role="page"> elemenst in it, each with its own identifier ("page1", "page2", "page3", etc.) - after the standard use of multi-page JQM features. Each page section contains an instance of a user control that contains image buttons. All this works well, with one problem - when the user goes from the standard "page1" to any other "page" and presses one of the image buttons, the code starts, the page reloads - and returns the user back to the default page - "page 1".

This is not good - I needed a way to allow the user to start the button and reload the page and stay on the page element that they were viewing - JQM runs these few pages with hash tags in the URL - so I found a line of code that I added to the page load event that was read:

`Protected Sub Page_Load (ByVal sender as object, ByVal e As System.EventArgs) processes Me.Load

  Me.Form.Attributes("onsubmit") = "this.action+=top.location.hash;" End Sub` 

I initially used the radio buttons in my user control - which JQM was "skinning", so they were displayed as buttons - and with this single line in the Page_Load event, the user could click the switch on any page element and the code behind the switches, will fire, and the page will reload with the user returning to the same "page" element that they clicked on - not so as to replace the switch with image buttons - when I add this line of code to the Page_Load event, the controls I mageButton completely ceases to function - when I click on the code that is in their click even in the code behind, it doesn’t fire - and none of the page-level events such as Page_Load or Page_PreRender - clicking on them now does absolutely nothing ....

Any thoughts on this?

+6
source share
2 answers

New answer to solve the second part of your question:

I found that asp.net web forms just don't work with multi-page jQuery Mobile scripts. Web forms require all web controls to be in the same <form /> element, which should span all jQuery Mobile pages ("virtual"). This is directly related to the fact that jQuery Mobile must have <form /> elements on each additional page for proper rendering and mail packages.

Instead, consider MVC.

+1
source

The problem is that <asp:ImageButton /> displays as <input type="image" /> , which is hidden by jQuery Mobile. Add to you a data file = "none" ImageButton, which will make jQuery Mobile display the control as it is.

 <asp:ImageButton id="MyButton" runat="server" data-role="none" /> 
0
source

All Articles