Last post Jul 07, 2011 04:31 PM by jkirkerx
Jul 06, 2011 06:51 AM|nccsbim071|LINK
I have created a custom server control. So far this control renders some html in the webpage. On submit of the page i need to take the values entered in the textbox of the server control and call some webservice to validate the input of the user. i don't
want to write this code in code behind of the page that this control is used in. I want all the validations to be written in the server control itself and if validation fails, Page.IsValid should be set to false. If the user input value in server control is
valid Page.IsValid will be true.
I am trying to achieve is the same functionality as google recaptcha. All user needs to do to use this control is to user the control in the page. user entered value is correct or incorrect is handled in the control itself and in the code behind of the page,
there is only Page.IsValid. Here is the page on google that explains this
and i have also used the google recaptcha and it works as expected. I also want to build same kind of functionality for my server control, Please help, if it is possible.
Jul 06, 2011 07:12 AM|Kulrom|LINK
You can just normally use the IsValid method in the server controls. Add some validators there and then use OnLoad event to check if page is valid. Just like you do it with standard Web Page.
Jul 06, 2011 11:18 PM|jkirkerx|LINK
Let me rephrase your request.
You want to make a server control, that outputs the html needed for 100% complete client side processing?
it's pretty much 100% done in the browsers memory.
In fact, this site is built using the same technology that I just described above.
The use of page.isvalid is for postbacks to the server.
Try the webserver forum
Jul 07, 2011 01:17 AM|nccsbim071|LINK
Thank's for answering the questions. I found the solution. Here is the entire code of the server control. The trick was to implement IValidator. It gives us two property and one metod. ErrorMessage and IsValid properties and Validate method. I wrote all
the validation code in Validate method and set this.IsValid. This solved the problem.
public class MyControl : WebControl, IValidator
protected override void RenderContents(HtmlTextWriter output)
//Render the required html
protected override void Render(HtmlTextWriter writer)
protected override void OnInit(EventArgs e)
public string ErrorMessage
public bool IsValid
public void Validate()
string code = Context.Request["txtCode"];
this.IsValid = Validate(code);//this method calls the webservice and returns true or false
ErrorMessage = "Invalid Code";
Jul 07, 2011 04:31 PM|jkirkerx|LINK
That's interesting. I too have put alot of time into form validations in the last year, in a pre and post emptive manner, to help customers fill out information in which I precieve to be the correct format.
I would like like to see an live example of this, to measure whethter or not it is more effective than what I have currently implemented.
I dumped the page.valid stuff, because I found it to be unreliable in the production or live enviroment. The validation group, and the require field validators worked fine in development, but for some reason in the production enviroment, they were not 100%
Pm me with a link for me to check out when your ready.