Click here to Skip to main content
16,017,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<telerik:RadCodeBlock ID="RadCodeBlock2"  runat="server">
    <script type="text/javascript" language="javascript">
        function validate() {

            var CompanyName = /^[A-Za-z0-9]{3,20}$/;
            var txtCompanyName = document.getElementById('<%=radtxtCompanyName.ClientID %>').value;

            if (!CompanyName.test(txtCompanyName)) {
                document.getElementById("<%=radtxtCompanyName.ClientID %>").style.borderColor = "red";

                return false;
            }
            else {
                document.getElementById("<%=radtxthidden.ClientID %>").Text = "validate";
            } }

    </script>
    </telerik:RadCodeBlock>

XML
<telerik:RadButton ID="RadBtnSubmit" Text="Submit"  runat="server" 
            BackColor="#3399FF" ForeColor="White" 
             Height="30px" Width="100px" ButtonType="LinkButton" AutoPostBack="true"
            OnClientClick="return validate()"  önClick ="RadBtnSubmit_Click" />

C#
protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        RadBtnSubmit.Attributes.Add("OnClick", "return validate()");

    }
    catch (Exception ex)
    {

        ErrorLogClass.SendError(ex, "abcd", "PageLoad");
    }
}

I am not able to perform validation if condition is incorrect onclick function is working and if onclick is executed then condition is not checked.Help me out in this friends.Thanks in advance.
Posted
v2

1 solution

First replace this line from your code:
C#
RadBtnSubmit.Attributes.Add("OnClick", "return validate()");

Also, in else block of your javascript validation function add:
JavaScript
return true;


Try this and reply if it doesn't work.
 
Share this answer
 
Comments
prashanth_866 3-Jan-13 6:25am    
RadBtnSubmit.Attributes.Add("OnClick", "return validate()");
What should i replace this with? .I tried adding return true also no use mate.
Zafar Sultan 3-Jan-13 6:31am    
Sorry, my mistake. you have to remove that line.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900