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

Posted by Community Admin on 03-Aug-2018 14:05

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

All Replies

Posted by Community Admin on 28-Apr-2011 00:00

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?

Posted by Community Admin on 28-Apr-2011 00:00

Using 4.1?

Posted by Community Admin on 28-Apr-2011 00:00

Sorry.  Yes, this is using version 4.1

Posted by Community Admin on 28-Apr-2011 00:00

Ok, I got nothin' then ;)

Does Ivans post here help at all

Posted by Community Admin on 28-Apr-2011 00:00

Nope, the post you linked to was also started by me.  I posted the code he requested and I still haven't heard back.

Posted by Community Admin on 28-Apr-2011 00:00

Oh geez, missed that, so sorry

I haven't had to do this yet, so I'm not sure...sorry about that

Posted by Community Admin on 28-Apr-2011 00:00

@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

Posted by Community Admin on 28-Apr-2011 00:00

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.

 

 

 

 

 

Posted by Community Admin on 28-Apr-2011 00:00

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

This thread is closed