Custom validator
-
Hi guys, I have a small problem, hope u could help me ! I'm tryin to use a custom validator on a Textbox ! Look : * The code behind now protected void first_CV_ServerValidate(object source, ServerValidateEventArgs args) { if (TextBox2.Text == "") { args.IsValid = false; } else { args.IsValid = true; } } Nothing changes if I set the
ValidateEmptyText
property of theCustomValidator
CustomValidator to true. Basically, I hoped to see a message when the Textbox is empty! But nothin happen when Click on my submit button Please help me -
Hi guys, I have a small problem, hope u could help me ! I'm tryin to use a custom validator on a Textbox ! Look : * The code behind now protected void first_CV_ServerValidate(object source, ServerValidateEventArgs args) { if (TextBox2.Text == "") { args.IsValid = false; } else { args.IsValid = true; } } Nothing changes if I set the
ValidateEmptyText
property of theCustomValidator
CustomValidator to true. Basically, I hoped to see a message when the Textbox is empty! But nothin happen when Click on my submit button Please help meWhy not use the RequiredFieldValidator [^]instead.
Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Why not use the RequiredFieldValidator [^]instead.
Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
REquiredFieldValidator
is not appropriated cuze I try use the control on a TextBox with avisible mode
is False in this case theRequiredFieldValidator
doesn't work. Help me about the custom validator, I think it's the only solution.Why do you want a custom validator even? You can just check the value of textbox before your processing begins and if its empty just display error message (whatever you want). For example on button click event you can check the value of textbox and avoid further action if its empty. HTH
Coding C# ExciteTemplate
-
Hi guys, I have a small problem, hope u could help me ! I'm tryin to use a custom validator on a Textbox ! Look : * The code behind now protected void first_CV_ServerValidate(object source, ServerValidateEventArgs args) { if (TextBox2.Text == "") { args.IsValid = false; } else { args.IsValid = true; } } Nothing changes if I set the
ValidateEmptyText
property of theCustomValidator
CustomValidator to true. Basically, I hoped to see a message when the Textbox is empty! But nothin happen when Click on my submit button Please help meI've run into this issue before as well where I had a textbox hidden and the requiredfield validator would mess the form up. I'm not sure what it is exactly you are attempting to pull off, but I've found it easier in some cases to just build the controls instead of hiding. For example, if you are hiding a textbox until someone clicks a button and then showing it, try this instead and then attach the required field validator to it....
TextBox tb1 = new TextBox();
RequiredFieldValidator re1 = new RequiredFieldValidator();
re1.ControltoValidate = tb1.ID;
divControl.Controls.add(tb1);The above code needs some tweaking..but should give you the idea. The validator won't screw up the form because the textbox doesn't even exist until you place it as a new control. :) That, or I've personally become quite fond of using javascript to validate forms...
var namebox = document.getElementById('<%= Name_textbox.ClientID %>');
if (namebox.value == ''){
var message = "We seem to be missing some information. Please correct the following items before submitting:\n\n";
if (namebox.value == '') {
message += "Name box cannot be blank.\n";
namebox.style.backgroundColor = 'yellow';
}hopefully this helps! good luck
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
-
I've run into this issue before as well where I had a textbox hidden and the requiredfield validator would mess the form up. I'm not sure what it is exactly you are attempting to pull off, but I've found it easier in some cases to just build the controls instead of hiding. For example, if you are hiding a textbox until someone clicks a button and then showing it, try this instead and then attach the required field validator to it....
TextBox tb1 = new TextBox();
RequiredFieldValidator re1 = new RequiredFieldValidator();
re1.ControltoValidate = tb1.ID;
divControl.Controls.add(tb1);The above code needs some tweaking..but should give you the idea. The validator won't screw up the form because the textbox doesn't even exist until you place it as a new control. :) That, or I've personally become quite fond of using javascript to validate forms...
var namebox = document.getElementById('<%= Name_textbox.ClientID %>');
if (namebox.value == ''){
var message = "We seem to be missing some information. Please correct the following items before submitting:\n\n";
if (namebox.value == '') {
message += "Name box cannot be blank.\n";
namebox.style.backgroundColor = 'yellow';
}hopefully this helps! good luck
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
-
Thanks compninja25 for helping, Can u even tell me which language U R using here, is dat ...?
Oh sorry. The top part is c#, and the bottom code block is javascript.
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.