Wednesday, March 23, 2011

Using two user controls on the same page?

Hello,

I have a user control in a master page and the same user control directly in the aspx. The user control in the master page works fine, but when I try the user control that is embedded directly in the aspx page, it doesn't work. The user control is 2 textboxes with a login button. What it looks like it is trying to do is when I enter my username and password for the embedded user control, it sees that the user controls textboxes that are in the master page are blank and it complains. Is there a way to handle this properly?

The event handler for the user control that is embedded directly in the page is not being called.

Here is the button for the login control:

<asp:ImageButton ID="ibtnLoginButton" runat="server" CommandName="Login"   
ImageUrl="~/images/sign-in.png"
ValidationGroup="ctl00$Login1" OnClick="LoginButton_OnClick"
meta:resourcekey="LoginButtonResource1" />
From stackoverflow
  • It sounds like your controls are sharing a ValidationGroup - can you post some code so we can see?

  • It is hard to tell exactly what the problem is without more information.

    From what you are saying, it could be client-side validation that kicks in. If this is the case, you could set ValidationGroup on the controls to the ID of the UserControl. Then the controls on the same instance of the UserControl will have the same validation group and thus be validated as a unit.

  • The issue must be within your custom user control which seems to not handle properly the fact that it can be used more than once in the same page.

    It's often caused by badly written JavaScript or the ValidationGroup property is the same for every instance of the user control.

0 comments:

Post a Comment