Validation
-
I'm trying to validate on client side with requiredfields but my big problem is if the page with requiredfields was activated when i want to go to another page am unable to click buttons cause nothing was putted on those required fields.So how do i control my requiredfields to only work on a certain click not on page activation. Tsepo "mafunwa" Barnabas DUT
-
I'm trying to validate on client side with requiredfields but my big problem is if the page with requiredfields was activated when i want to go to another page am unable to click buttons cause nothing was putted on those required fields.So how do i control my requiredfields to only work on a certain click not on page activation. Tsepo "mafunwa" Barnabas DUT
Set the
Page_ValidationActive
javascript variable to false in the button's OnClick event. This works: In your ASPX (had to remove beginning angle brackets to get it to render on CP :) ):<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Untitled Page asp:RequiredFieldValidator runat="server" id="rfv" ControlToValidate="txt" ErrorMessage="Error"> asp:TextBox runat="server" ID="txt"> asp:Button runat="server" ID="btn" Text="Go" OnClick="btn\_Click" /> function TurnOffVal() { Page\_ValidationActive = false; }
And in the code behind:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
btn.Attributes.Add("onclick", "TurnOffVal();");
}
protected void btn_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.codeproject.com");
}
}
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.