2

I have a similar problem to the one described in this other question: aspnet webforms disable button on submit. My ASP.NET Web Forms site works fine before I added jQuery and jQuery mobile. After installing those packages with NuGet, the code for my image button is ignored. A simple button had a similar problem to the image button until I set UseSubmitBehavior="true". Disabling jQuery Mobile is enough to re-enable the button functionality. Also there is a strange problem that the 'View Source' of IE10 returns the previous page's markup while the developer menu shows the actual XHTML - I don't know if that is relevant.

My code should normally be run after an image button click Protected Sub BTNtoggleHole_Click(sender As Object, e As ImageClickEventArgs) Handles BTNtoggleHole.Click but it refuses so I have forced it to run in Public Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load. Is there some page lifecycle stuff I'm missing?

The following is the button that no longer triggers any server side code:

<asp:ImageButton ID="BTNtoggleHole" runat="server" Style="float: right;" ImageUrl="~/Images/Buttons/Handicaps/9-hole-toggle.png" CausesValidation="False" ClientIDMode="Inherit" AlternateText="18/9 hole toggle" />

Clicking the button causes a postback regardless of whether or not the jQuery is commented out, not present, or disabled.

Community
  • 1
  • 1
haleonj
  • 1,438
  • 3
  • 16
  • 30
  • Does clicking it cause a post-back at all? What's different about that post-back's request values before and after the change? Are you using any jQuery code which modifies the client-side code at all? – David Sep 30 '13 at 13:20
  • What do you mean by "added jQuery and jQuery mobile", does that mean just the mere script references or actual script logic? If logic, then post that please. – Karl Anderson Sep 30 '13 at 13:45
  • @David I added data-role="none" to the ImageButton. Although this attribute should disable any jQuery/JavaScript for that button it changes nothing - the BTNtoggleHole_Click method is never called either way. Other elements do use jQuery Mobile's data roles such as collapsible. Also, yes the button causes a post-back. – haleonj Sep 30 '13 at 14:58
  • 1
    I would look at the difference between the rendered HTML of that ImageButton (with and without jQuery). It sounds like whatever you're using jQuery for is overwriting what ASP.NET uses to cause a PostBack. – Josh Darnell Sep 30 '13 at 15:36
  • @KarlAnderson I added the script references in the master page. Disabling all script references enables the BTNtoggleHole_Click method.I use no custom scripts and I do not modify the logic of jQuery but I do use the normal data roles such as collapsible. The only parent element using jQuery would be the div with data-role="content" and body with data-role="page". Commenting out the script references enables the button's method. – haleonj Sep 30 '13 at 15:45
  • @jadarnel27 The rendered output with and without script enabled is the same. – haleonj Sep 30 '13 at 15:55
  • Apparently jQuery Mobile and WebForms were not meant to be. There is a [blog](http://scottnorberg.blogspot.com/2011/11/mixing-jquery-mobile-and-aspnet.html) post that still seems relevant. – haleonj Oct 02 '13 at 19:58

1 Answers1

0

I ran into something similar with LinkButtons. It turned out to be an issue with certain mobile browsers and the way the control's javascript was handled. You can set ClientTarget="uplevel" for certain browsers to fix the issue. I added the following in a base class for my pages so get things straight:

    ' HACK: This is needed to get LinkButtons working in Chrome for Mobile (on iOS)
    ' This has to be in the page and cannot be in the masterpage or control.
    ' https://stackoverflow.com/questions/11591776/chrome-on-ipad-not-working-with-asp-net-4
    Protected Overrides Sub OnPreInit(ByVal e As System.EventArgs)
        If Request.UserAgent IsNot Nothing AndAlso _
            (Request.UserAgent.IndexOf("AppleWebKit") > -1 OrElse _
             Request.UserAgent.IndexOf("chrome") > -1 OrElse _
             Request.UserAgent.IndexOf("crios") > -1) Then
            Me.ClientTarget = "uplevel"
        End If
        MyBase.OnPreInit(e)
    End Sub

Again, this worked for me for LinKButtons, but the ImageButton might be very similar. See this SO question for more details: Chrome on iPad not working with ASP.NET 4

Community
  • 1
  • 1
Brent Keller
  • 1,385
  • 1
  • 12
  • 17