Custom Validation inside Repeater
-
I have to validate SSN which will be entered in 3 different textboxes (txtSSN1, txtSSN2, txtSSN3). 1. If SSN1 is entered and other TWO textboxes are left blank, then CustomValidater should raise an error. 2. If all 3 textboxes are blank, then is a valid scenario. return true and save. 3. If all 3 textboxes are entered with values, return true. As I have these controls in a Repeater, I cann't able to find the controls from clientside. Need help
Regards, Ravi K. Kalyan
-
I have to validate SSN which will be entered in 3 different textboxes (txtSSN1, txtSSN2, txtSSN3). 1. If SSN1 is entered and other TWO textboxes are left blank, then CustomValidater should raise an error. 2. If all 3 textboxes are blank, then is a valid scenario. return true and save. 3. If all 3 textboxes are entered with values, return true. As I have these controls in a Repeater, I cann't able to find the controls from clientside. Need help
Regards, Ravi K. Kalyan
-
I have to validate SSN which will be entered in 3 different textboxes (txtSSN1, txtSSN2, txtSSN3). 1. If SSN1 is entered and other TWO textboxes are left blank, then CustomValidater should raise an error. 2. If all 3 textboxes are blank, then is a valid scenario. return true and save. 3. If all 3 textboxes are entered with values, return true. As I have these controls in a Repeater, I cann't able to find the controls from clientside. Need help
Regards, Ravi K. Kalyan
What is the problem with that. Repeater actually places the same html that you define in
ItemTemplate
andAlternateItemTemplate
. You can easily use OnItemDataBound event to find the controls. Inside it write like this: if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternateItem) { TextBox tb = e.Item.FindControl("yourserversideiD"); tb.Attributes.Add("onblur", yourjavascript); } Like this way you can easily find any serverside control inside Repeater and apply your javascript. so try this out.. :rose:Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
What is the problem with that. Repeater actually places the same html that you define in
ItemTemplate
andAlternateItemTemplate
. You can easily use OnItemDataBound event to find the controls. Inside it write like this: if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternateItem) { TextBox tb = e.Item.FindControl("yourserversideiD"); tb.Attributes.Add("onblur", yourjavascript); } Like this way you can easily find any serverside control inside Repeater and apply your javascript. so try this out.. :rose:Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using JavascriptGuys, Thanks for the reply. All I need is a client side validation. Server side is just a matter of 20min for me... I'm looking for a client side validation. Thanks
Regards, Ravi K. Kalyan
-
Guys, Thanks for the reply. All I need is a client side validation. Server side is just a matter of 20min for me... I'm looking for a client side validation. Thanks
Regards, Ravi K. Kalyan
Hey Ravi... Believe me.. I was really talking about client side validation in the code above. onblur is a client side event, I think. Just place your javascript there. Call the validation javascript from there. if you pass like this :
txt.Attributes.Add("onblur", "javascript:func(this)")
you will get the txtbox on the function. Also you might usetxt.ClientId
to pass the id. :)Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
Hey Ravi... Believe me.. I was really talking about client side validation in the code above. onblur is a client side event, I think. Just place your javascript there. Call the validation javascript from there. if you pass like this :
txt.Attributes.Add("onblur", "javascript:func(this)")
you will get the txtbox on the function. Also you might usetxt.ClientId
to pass the id. :)Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using JavascriptMy requirement is to validate the SSN in Save_Click event. NOT in "Onblur" event. I also have "Add Child" button using which I'm adding new Repeater.. So I can add N number of children before clicking on save button. And each repeater is having SSN1, SSN2 and SSN3 textboxes that I need to validate. Thanks for the replies. Ravi
Regards, Ravi K. Kalyan
-
My requirement is to validate the SSN in Save_Click event. NOT in "Onblur" event. I also have "Add Child" button using which I'm adding new Repeater.. So I can add N number of children before clicking on save button. And each repeater is having SSN1, SSN2 and SSN3 textboxes that I need to validate. Thanks for the replies. Ravi
Regards, Ravi K. Kalyan
Ok.. so for each SSN1, SSN2 and SSN3 you will be having one button.. So do like this :
Button btn = e.Item.FindControl("yourbuttonid");
TextBox SSN1 = e.Item.FindControl("SSN1ID");
TextBox SSN2 = e.Item.FindControl("SSN2ID");
TextBox SSN3 = e.Item.FindControl("SSN3ID");
string script = "javascript:validate('" + SSN1.ClientId + "','" + SSN2.ClientId + "','" + SSN3.ClientId + "');";
btn.Attributes.Add("onclick", script);Now in the page designer, place a script tag and add a function
validate
:function validate(ssn1id, ssn2id, ssn3id){
var ssn1 = document.getElementById(ssn1id);
var ssn2 = document.getElementById(ssn2id);
var ssn3 = document.getElementById(ssn3id);// do the logic here.
}
I home this is what you wanted. :thumbsup:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript