I'm having some trouble with one of my macros which contains a usercontrol. The usercontrol contains some textboxes with validation (asp.net validation) and a button for submitting the data.
Now, the problem is that when a user places two or more of this macro on a page, it will validate all of the textboxes whenever a client clicks on one of the buttons. Of course, this is due to the asp.net controls having the same ID, but even if I try to, programatically, assign an unique id (using a GUID) to both the validation group, the controls and the validators, it still tries to validate all of the textfields.
It feels like I have missed something really basic here, just can't see what it is.
You're using validation groups I assume? I think that you have to check that the group is vaild where as before you checked page.IsValid (my memories of .NET validation are a little rusty to be honest)
I tried to perform a manual validation of the group, but with no result. I think the error is caused by assigning a new unique id to the controls and validation group before the actual validation when I click a button. Guess I have to rethink my structure as it's not pretty to have several asp.net controls with the same ID on the same page.
Multiple macros with the same usercontrol
Hi all,
I'm having some trouble with one of my macros which contains a usercontrol. The usercontrol contains some textboxes with validation (asp.net validation) and a button for submitting the data.
Now, the problem is that when a user places two or more of this macro on a page, it will validate all of the textboxes whenever a client clicks on one of the buttons. Of course, this is due to the asp.net controls having the same ID, but even if I try to, programatically, assign an unique id (using a GUID) to both the validation group, the controls and the validators, it still tries to validate all of the textfields.
It feels like I have missed something really basic here, just can't see what it is.
Any help/hint is greatly appreciated!
All the best,
Bo
Hey Bo,
I think this is a .NET issue right?
You're using validation groups I assume? I think that you have to check that the group is vaild where as before you checked page.IsValid (my memories of .NET validation are a little rusty to be honest)
Rich
Hi Rich,
Thanks for your reply :) Appreciated!
I tried to perform a manual validation of the group, but with no result. I think the error is caused by assigning a new unique id to the controls and validation group before the actual validation when I click a button. Guess I have to rethink my structure as it's not pretty to have several asp.net controls with the same ID on the same page.
Thanks again! :)
- Bo
Alright I finally came up with a solution to this!
All I did was making a new unique string and assign it to a property on the usercontrol:
UniqueId = Guid.NewGuid().ToString();
public string UniqueId { get; set; }
Then I set all of the controls validationgroup to this property and everything worked like it should!
- Bo
is working on a reply...