Click here to Skip to main content
14,364,290 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi all!,

i have using on client side validation with and using the buton click event
Page.Validate("Register")
            If Page.IsValid Then
'-------------code
endif


but it is not vlid it show page.IsValild is false.
Posted
Updated 2-Nov-19 3:17am
Comments
ZurdoDev 16-Apr-12 16:12pm
   
So, what is the question?
DINESH K MAURYA 17-Apr-12 0:43am
   
my question is how to validate true in server side.
because my validation is false as i show in code(page.IsValid)
how to validation true here...
Rate this:
Please Sign up or sign in to vote.

Solution 1

are you using validations controls, right? this controls first try to validate on client side, so, event will be fired only if is valid or if js is disabled on client bronwser. On code behind you need to verify manually.

<div>
        <asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
        <asp:requiredfieldvalidator xmlns:asp="#unknown">
        ID="rfv1" runat="server" ErrorMessage="*" ControlToValidate="TextBox1">
        </asp:requiredfieldvalidator>
        <br />
        <asp:button id="Button1" runat="server" text="Button" xmlns:asp="#unknown" />
        <br />
        <asp:literal id="Literal1" runat="server" xmlns:asp="#unknown"></asp:literal>
    </div>


code behind:

void Button1_Click(object sender, EventArgs e)
    {
        Page.Validate();
        if (Page.IsValid)
        {
            Literal1.Text = "valid";
        }
        else
        {
            Literal1.Text = "not valid";
        }
        
    }
   
Comments
DINESH K MAURYA 17-Apr-12 0:49am
   
thank for..
but i use ValidationGroup for many clintside control as two three textbox.

<td align="left" valign="top" width="25%">
<asp:TextBox runat="server" ID="txtEmailID" Width="50%" MaxLength="50" onpaste="return false"
oncopy="return false" oncut="return false" CssClass="unwatermarked">
<asp:RequiredFieldValidator ID="rfvTxtEmail" runat="server" ControlToValidate="txtEmailID"
ValidationGroup="Register" ErrorMessage="Required Field Missing<br />Please type your Email ID"
Display="None" />
</td>

second text

<td align="left" valign="top" width="25%">
<asp:TextBox runat="server" ID="txtPSWD" MaxLength="30" TextMode="Password" onpaste="return false"
oncopy="return false" oncut="return false" Width="50%" CssClass="unwatermarked">
<cc1:TextBoxWatermarkExtender ID="tbwPasword" runat="server" TargetControlID="txtPSWD"
WatermarkText="....." WatermarkCssClass="watermarked">

<asp:RequiredFieldValidator ID="rfvPassword" runat="server" ErrorMessage="Required Field Missing<br/>Please type Password"
Display="None" ControlToValidate="txtPSWD" SetFocusOnError="True" ValidationGroup="Register">
</td>


<td align="right" width="35%">
<asp:Button ID="btnRegester" runat="server" Text="Save" ValidationGroup="Register"
CausesValidation="true" Height="30px" Width="90px" CssClass="savebutton" />
</td>

i use button click event validation in serverside.
Please how to solve it,...
sayadian 13-Feb-16 6:52am
   
hg
Rate this:
Please Sign up or sign in to vote.

Solution 2

<asp:CustomValidator ID="cusValChecks" runat="server" Display="None" OnServerValidate="cusValChecks_ServerValidate"></asp:CustomValidator>


protected void cusValChecks_ServerValidate()
{
    IsValid = true;

    if (txtName.Text.Trim() == "")
            {
                lblError.Text = "Invalid";
                IsValid = false;
            }
}


void Button1_Click(object sender, EventArgs e)
{
    if (!Page.IsValid)
            {
                return;
            }
}
   
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100