Today, I was working on customvalidate a custom control in wizard. I spent whole morning trying to get customvalidator working. But unfortunately, the custom control can’t be found by document.getElementById.

Anyway, I just put some code so next time you can have an example to create a custom validator.

in Web page:

<asp:CustomValidator ID=”rfvBillable” ClientValidationFunction=”ValidateTextbox” runat=”server” ErrorMessage=”Billable is required.”>*</asp:CustomValidator>

in code:

        private void RegisterScipts()
            if (!Page.ClientScript.IsStartupScriptRegistered(“Startup”))
                // Form the script to be registered at client side.
                String scriptString = “<script language=\”JavaScript\”> function ValidateTextbox(source, args) {“;
                scriptString += “var value=document.getElementById(‘” + AdhocTimesheetDate.ClientID + “‘).value;”;
                scriptString += “if(value.length >0 ){args.IsValid=true;}”;
                scriptString += “else{args.IsValid=false;}”;
                scriptString += “}<“;
                scriptString += “/”;
                scriptString += “script>”;
                Page.ClientScript.RegisterStartupScript(typeof(Page), “Startup”, scriptString);


You need to Page.ClientScript.RegisterStartupScript in .Net 3.5