ASP.NET Buttons don't work in my web user control
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?
Using 4.1?
Sorry. Yes, this is using version 4.1
Ok, I got nothin' then ;)
Does Ivans post here help at all
Nope, the post you linked to was also started by me. I posted the code he requested and I still haven't heard back.
Oh geez, missed that, so sorry
I haven't had to do this yet, so I'm not sure...sorry about that
@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
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;
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