More in this section

Forums / General Discussions / ASP.NET Buttons don't work in my web user control

ASP.NET Buttons don't work in my web user control

9 posts, 0 answered
  1. Chris
    Chris avatar
    21 posts
    Registered:
    16 Aug 2010
    28 Apr 2011
    Link to this post
    I created a web user control for my client to drag-and-drop on their page.  In this control, there are a couple text fields and a "Send" button.  It's a standard ASP.NET ImageButton with the "OnClick" event wired to my "Send_Click" method.

    The problem is, when I click the button nothing happens.  I tried setting the page to have "Enable Viewstate" checked, but it still doesn't work.

    How can I make my control function correctly?
  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    28 Apr 2011
    Link to this post
    Using 4.1?
  3. Chris
    Chris avatar
    21 posts
    Registered:
    16 Aug 2010
    28 Apr 2011
    Link to this post
    Sorry.  Yes, this is using version 4.1
  4. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    28 Apr 2011
    Link to this post
    Ok, I got nothin' then ;)

    Does Ivans post here help at all
  5. Chris
    Chris avatar
    21 posts
    Registered:
    16 Aug 2010
    28 Apr 2011
    Link to this post
    Nope, the post you linked to was also started by me.  I posted the code he requested and I still haven't heard back.
  6. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    28 Apr 2011
    Link to this post
    Oh geez, missed that, so sorry

    I haven't had to do this yet, so I'm not sure...sorry about that
  7. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    28 Apr 2011
    Link to this post
    @Chris, I'm curious if you've tried this with a standard asp:Button instead of an ImageButton. It would be interesting to see if the issue is a case form not submitting at all or if it's an issue with ImageButton. I only suggest this as I have a Form I created in a UserControl and submit it with an asp:Button (styled using CSS) and it works fine in 4.1

    So not a solution but maybe help narrow down the issue.

    Cheers,
    Phill
  8. Chris
    Chris avatar
    21 posts
    Registered:
    16 Aug 2010
    28 Apr 2011
    Link to this post
    I tried changing it to a standard button and it's still not working.  What I'm finding odd is other various properties that are getting rendered to the HTML.

    The button has an "onclick" getting added to it with this value: "

    javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$MainContentPlaceHolder$Resources$T6F9DDBF3011$SendButton", "", true, "", "", false, false))".  But since it's a standard button meant to cause a post, there shouldn't be an "onclick".

    Also, the form tag has

    onsubmit="javascript:return WebForm_OnSubmit();".  This onsubmit property is likely injected onto the tag because I have some client side RequiredFieldValidators.  This function is:

    function WebForm_OnSubmit() { 
    if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
    return true;

    }

    Unfortunately, I couldn't get my browser to hit this funtion when clicking the button, likely because of the "WebForm_DoPostBackWithOptions..." on the onclick of the button.  I generally don't use client side validators (so I don't have a lot of experience with them) but I have to in this case because my button is in a popup (the user clicks a link, a fancybox pops up with a couple text boxes and the send button).  I don't want to postback to do validation because then I need to determine whether or not to open up my fancybox again based on success or failure of the validation. 

    I suppose my other option is to forgo the asp.net RequiredFieldValidators and just write my own javascript to validate

    (a few minutes later...)

    I just ran a test and commented out my validators.  The weird "WebForm_DoPostBackWithOptions..." disappeared, as did the "onsubmit" on the form tag.  Unfortunately, my ImageButton still doesn't hit my break point.  Doesn't hit my breakpoint using a regular button, either.

     

     

     

     

     

  9. Keith
    Keith avatar
    8 posts
    Registered:
    25 Oct 2010
    28 Apr 2011
    Link to this post
    Chris,

    The WebForm_PostBackOptions and WebForm_OnSubmit are generated by ASP.Net. They're how the controls work with the validators and do their post backs.

    I'm curious, are there other validators not in your control on the page? If there are, they could be prohibiting the post back of your control. Just as a test, you could set the CausesValidation property on your submit button to false to see if it'll post back that way.

    If there are more validators on the page you'll have to set the ValidationGroup property on the controls in your user control so they don't interact with the other validators.

    HTH,
    Keith
9 posts, 0 answered