 |
| ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 8th, 2012, 03:24 AM
|
|
Authorized User
|
|
Join Date: Aug 2012
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Aspx page implemented with javascript validator
Hello there.
First of all I must say that I am a newbie when it comes to net (C#).
My reference book is:
BEGINNING ASP.NET 4 IN C# AND VB
IN C# AND VB
Spaanjaars Imar.
Here is my problem with this aspx page implemented with javascript function validator:
- I need show in the javascript alert the ErrorMessage "The field is required", when validations is enabled;
- The aspx page and my GridView is not updated after inserting interval DateStart and DateEnd, why?
- The aspx page and my GridView is not updated after inserting interval DateStart1 and DateEnd1, why?
Can you help me?
If you have link for similar task, please give it me.
Can you explain any one or any sample code related this.
Your help would be very appreciated.
Thanks in advance for your time and hints.
Cheers.
Chevy Mark Sunderland (cms)
code-behind
Code:
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.ComponentModel;
using System.Threading;
using System.Globalization;
using System.Text;
public partial class COV2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// query ...
GridViewBind();
dadapter.Dispose();
ConnSqlServer.Close();
ConnSqlServer.Dispose();
}
}
public void GridViewBind()
{
// query ...
dadapter = new SqlDataAdapter(sql1, ConnSqlServer);
dset = new DataSet();
dset.Clear();
dadapter.Fill(dset);
GridView1.PageIndex = 0;
GridView1.DataSource = dset.Tables[0];
GridView1.DataBind();
dadapter.Dispose();
Response.Write(sql1);
}
protected void Button1_Click(Object sender, EventArgs e)
{
GridViewBind();
}
protected void Button2_Click(Object sender, EventArgs e)
{
GridViewBind();
}
}
MyPage.aspx:
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="button.aspx.cs" Inherits="SqlServer_button" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body onload="InitValidators()">
<form id="form1" runat="server">
<div>
<asp:ValidationSummary ID="ValidationSummary1" ShowMessageBox="true" runat="server"
ShowSummary="false" />
<asp:TextBox ID="DateStart" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DateStart"
ErrorMessage="RequiredFieldValidator" Display="None"></asp:RequiredFieldValidator>
<asp:TextBox ID="DateEnd" runat="server"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Not valid date!"
ControlToValidate="DateEnd" ControlToCompare="DateStart" Type="Date" Operator="GreaterThanEqual"
CssClass="redb" SetFocusOnError="false"></asp:CompareValidator>
<asp:ImageButton ID="Button1" ImageUrl="images/cerca_icon.gif" runat="server" OnClick="Button1_Click"
OnClientClick="javascript:InitValidators();return false;" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DateEnd"
ErrorMessage="RequiredFieldValidator" Display="None"></asp:RequiredFieldValidator>
<br />
<br />
<asp:TextBox ID="DateStart1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="DateStart1"
ErrorMessage="RequiredFieldValidator" Display="None"></asp:RequiredFieldValidator>
<asp:TextBox ID="DateEnd1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="DateEnd1"
ErrorMessage="RequiredFieldValidator" Display="None"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator2" runat="server" ErrorMessage="Not valid date!"
ControlToValidate="DateEnd1" ControlToCompare="DateStart1" Type="Date" Operator="GreaterThanEqual"
CssClass="redb" SetFocusOnError="false"></asp:CompareValidator>
<asp:ImageButton ID="Button2" ImageUrl="images/cerca_icon.gif" runat="server" OnClick="Button2_Click"
OnClientClick="javascript:InitValidators();return false;" />
<asp:Label ID="MessagesLabel" runat="server" Text=""></asp:Label>
<br />
<br />
</div>
</form>
<script type="text/javascript" language="javascript">
function InitValidators() {
var DateStart = document.getElementById('<%=DateStart.ClientID%>');
var DateEnd = document.getElementById('<%=DateEnd.ClientID%>')
var DateStart1 = document.getElementById('<%=DateStart1.ClientID%>');
var DateEnd1 = document.getElementById('<%=DateEnd1.ClientID%>')
if (DateStart.value == '' || DateEnd.value == '') {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator1.ClientID%>'), true);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator2.ClientID%>'), true);
}
else {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator1.ClientID%>'), false);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator2.ClientID%>'), false);
}
if (DateStart1.value == '' || DateEnd1.value == '') {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator3.ClientID%>'), true);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator4.ClientID%>'), true);
}
else {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator3.ClientID%>'), false);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator4.ClientID%>'), false);
}
}
</script>
</body>
</html>
|
|

August 8th, 2012, 03:38 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Is this the correct code? There seems to be missing quite a bit. Most notably: the GridView in the markup that you're binidng in Code Behind....
Cheers,
Imar
|
|

August 8th, 2012, 03:47 AM
|
|
Authorized User
|
|
Join Date: Aug 2012
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Imar
Is this the correct code? There seems to be missing quite a bit. Most notably: the GridView in the markup that you're binidng in Code Behind....
Cheers,
Imar
|
Thank you for reply.
This is the code-behind complete and working; I have hidden in code-behind only the queries run where condition.
Code:
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.ComponentModel;
using System.Threading;
using System.Globalization;
using System.Text;
public partial class COV2 : System.Web.UI.Page
{
SqlDataAdapter dadapter;
DataSet dset;
string sql;
string sql1;
string sql2;
string sql3;
string sql4;
SqlConnection ConnSqlServer =
new SqlConnection(ConfigurationManager.ConnectionStrings["ConnSqlServer"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ConnSqlServer.Open();
//START MAT
sql2 = "SELECT .... ;";
dadapter = new SqlDataAdapter(sql2, ConnSqlServer);
dset = new DataSet();
dadapter.Fill(dset);
DropDownList3.DataSource = dset.Tables[0];
DropDownList3.DataTextField = "MAT";
DropDownList3.DataValueField = "Sort";
DropDownList3.DataBind();
//END MAT
//START DTR
sql4 = "SELECT ...;";
dadapter = new SqlDataAdapter(sql4, ConnSqlServer);
dset = new DataSet();
dadapter.Fill(dset);
DropDownList6.DataSource = dset.Tables[0];
DropDownList6.DataTextField = "DTR";
DropDownList6.DataValueField = "Sort";
DropDownList6.DataBind();
//END DTR
GridViewBind();
dadapter.Dispose();
ConnSqlServer.Close();
ConnSqlServer.Dispose();
}
}
public void GridViewBind()
{
sql1 = "SELECT ....;";
if (!string.IsNullOrEmpty(DateStart.Text) && !string.IsNullOrEmpty(DateEnd.Text))
{
sql1 = "select ...;";
}
if (!string.IsNullOrEmpty(DateStart1.Text) && !string.IsNullOrEmpty(DateEnd1.Text))
{
sql1 = "select ....;";
}
if (DropDownList3.SelectedIndex != 0)
{
if (DropDownList3.SelectedIndex == 1)
{
sql1 = "SELECT ...;";
}
if (DropDownList3.SelectedIndex == 2)
{
sql1 = "SELECT ...;";
}
if (DropDownList3.SelectedIndex == 3)
{
sql1 = "SELECT ...;";
}
if (DropDownList3.SelectedIndex == 4)
{
sql1 = "SELECT ...;";
}
}
if (DropDownList6.SelectedIndex != 0)
{
if (DropDownList6.SelectedIndex == 1)
{
sql1 = "SELECT ...;";
}
if (DropDownList6.SelectedIndex == 2)
{
sql1 = "SELECT ...;";C;";
}
if (DropDownList6.SelectedIndex == 3)
{
sql1 = "SELECT ...;";
}
if (DropDownList6.SelectedIndex == 4)
{
sql1 = "SELECT ...;";
}
if (DropDownList6.SelectedIndex == 5)
{
sql1 = "SELECT ...;";
}
if (DropDownList6.SelectedIndex == 6)
{
sql1 = "SELECT ...;";
}
if (DropDownList6.SelectedIndex == 7)
{
sql1 = "SELECT ...;";
}
if (DropDownList6.SelectedIndex == 8)
{
sql1 = "SELECT ...;";
}
if (DropDownList6.SelectedIndex == 9)
{
sql1 = "SELECT ...;";
}
if (DropDownList6.SelectedIndex == 10)
{
sql1 = "SELECT ...;";
}
if (DropDownList6.SelectedIndex == 11)
{
sql1 = "SELECT ...;";
}
}
dadapter = new SqlDataAdapter(sql1, ConnSqlServer);
dset = new DataSet();
dset.Clear();
dadapter.Fill(dset);
GridView1.PageIndex = 0;
GridView1.DataSource = dset.Tables[0];
GridView1.DataBind();
dadapter.Dispose();
Response.Write(sql1);
}
protected void Button1_Click(Object sender, EventArgs e)
{
GridViewBind();
}
protected void Button2_Click(Object sender, EventArgs e)
{
GridViewBind();
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
DateStart.Text = "";
DateEnd.Text = "";
DateStart1.Text = "";
DateEnd1.Text = "";
DropDownList6.SelectedIndex = -1;
GridViewBind();
}
protected void DropDownList6_SelectedIndexChanged(object sender, EventArgs e)
{
DateStart.Text = "";
DateEnd.Text = "";
DateStart1.Text = "";
DateEnd1.Text = "";
DropDownList3.SelectedIndex = -1;
GridViewBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridViewBind();
GridView1.DataSource = dset.Tables[0];
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
}
Last edited by cms9651; August 8th, 2012 at 03:50 AM..
|
|

August 8th, 2012, 03:53 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
But where is the GridView? And where's the code that should update your database?
Imar
|
|

August 8th, 2012, 04:11 AM
|
|
Authorized User
|
|
Join Date: Aug 2012
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Imar
But where is the GridView? And where's the code that should update your database?
Imar
|
I'm sorry error to copy/paste... this is my page.aspx with GridView.
I don't need update values in the database, I need update only the view of GridView when I use the filtering in my web page.
E.g.: Use the filter for between date (DateStart and DataEnd) and in GridView I see only records between for this date.
Code:
<%@ Page Language="C#" AutoEventWireup="true" Culture="it-IT" CodeFile="COV2.aspx.cs"
Inherits="COV2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body onload="InitValidators()">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager" EnableScriptGlobalization="true" EnableScriptLocalization="true"
runat="server">
</asp:ScriptManager>
<div>
<asp:TextBox ID="DateStart" runat="server" Width="70"></asp:TextBox>
<img src="Images/calen.gif" id="Img1" alt="DateStart" onmouseover="this.style.cursor='pointer'"
onmouseout="this.style.cursor='default'" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="DateStart"
PopupButtonID="Img1" Format="dd/MM/yyyy" Animated="true">
</ajaxToolkit:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DateStart"
ErrorMessage="Start" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="DateStart"
ErrorMessage="Invalid date" Display="Dynamic" CssClass="redb" ValidationExpression="^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d$">
</asp:RegularExpressionValidator>
<asp:TextBox ID="DateEnd" runat="server" Width="70"></asp:TextBox>
<img src="Images/calen.gif" id="Img2" alt="End" onmouseover="this.style.cursor='pointer'"
onmouseout="this.style.cursor='default'" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="DateEnd"
PopupButtonID="Img2" Format="dd/MM/yyyy" Animated="true">
</ajaxToolkit:CalendarExtender>
<asp:ImageButton ID="Button1" ImageUrl="images/icon.gif" runat="server" OnClick="Button1_Click"
OnClientClick="javascript:return InitValidators();return false;" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DateEnd"
ErrorMessage="End" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="DateEnd"
ErrorMessage="Invalid date" Display="Dynamic" CssClass="redb" ValidationExpression="^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d$">
</asp:RegularExpressionValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Invalid Date"
ControlToValidate="DateEnd" ControlToCompare="DateStart" Type="Date"
Operator="GreaterThanEqual" CssClass="redb" SetFocusOnError="false" Display="Dynamic">
</asp:CompareValidator>
<asp:DropDownList ID="DropDownList3" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
Font-Size="10pt" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged">
<asp:ListItem Value="%">---</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList6" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
Font-Size="10pt" OnSelectedIndexChanged="DropDownList6_SelectedIndexChanged">
<asp:ListItem Value="%">---</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="DateStart1" runat="server" Width="70"></asp:TextBox>
<img src="Images/calen.gif" id="Img3" alt="Start" onmouseover="this.style.cursor='pointer'"
onmouseout="this.style.cursor='default'" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender3" runat="server" TargetControlID="DateStart1"
PopupButtonID="Img3" Format="dd/MM/yyyy" Animated="true">
</ajaxToolkit:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="DateStart1"
ErrorMessage="Start" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="DateStart1"
ErrorMessage="Invalid date" Display="Dynamic" CssClass="redb" ValidationExpression="^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d$">
</asp:RegularExpressionValidator>
<asp:TextBox ID="DateEnd1" runat="server" Width="70"></asp:TextBox>
<img src="Images/calen.gif" id="Img4" alt="End" onmouseover="this.style.cursor='pointer'"
onmouseout="this.style.cursor='default'" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender4" runat="server" TargetControlID="DateEnd1"
PopupButtonID="Img4" Format="dd/MM/yyyy" Animated="true">
</ajaxToolkit:CalendarExtender>
<asp:ImageButton ID="Button2" ImageUrl="images/icon.gif" runat="server" OnClick="Button2_Click"
OnClientClick="javascript:InitValidators();return false;" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="DateEnd1"
ErrorMessage="End" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="DateEnd1"
ErrorMessage="Invalid date" Display="Dynamic" CssClass="redb" ValidationExpression="^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d$">
</asp:RegularExpressionValidator>
<asp:CompareValidator ID="CompareValidator2" runat="server" ErrorMessage="Invalid Date"
ControlToValidate="DateEnd1" ControlToCompare="DateStart1" Type="Date"
Operator="GreaterThanEqual" CssClass="redb" SetFocusOnError="false" Display="Dynamic">
</asp:CompareValidator>
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
PageSize="25" ShowHeader="true" OnPageIndexChanging="GridView1_PageIndexChanging">
<Columns>
<asp:BoundField DataField="DateStart" HeaderText="DateStart" />
<asp:BoundField DataField="DateEnd" HeaderText="Datend" />
<asp:BoundField DataField="DateStart1" HeaderText="DateStart1" />
<asp:BoundField DataField="DateEnd1" HeaderText="Datend1" />
<asp:BoundField DataField="sID" HeaderText="sID" />
</Columns>
</asp:GridView>
<asp:DataList ID="DataList1" runat="server" RepeatLayout="Table" RepeatColumns="3"
CellPadding="2" CellSpacing="2">
<ItemTemplate>
</ItemTemplate>
</asp:DataList>
</div>
<asp:ValidationSummary ID="ValidationSummary1" ShowMessageBox="true" runat="server"
ShowSummary="false" />
<script type="text/javascript" language="javascript">
function InitValidators() {
var DateStart = document.getElementById('<%=DateStart.ClientID%>');
var DateEnd = document.getElementById('<%=DateEnd.ClientID%>')
var DateStart1 = document.getElementById('<%=DateStart1.ClientID%>');
var DateEnd1 = document.getElementById('<%=DateEnd1.ClientID%>')
if (DateStart.value == '' || DateEnd.value == '') {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator1.ClientID%>'), true);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator2.ClientID%>'), true);
}
else {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator1.ClientID%>'), false);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator2.ClientID%>'), false);
}
if (DateStart1.value == '' || DateEnd1.value == '') {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator3.ClientID%>'), true);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator4.ClientID%>'), true);
}
else {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator3.ClientID%>'), false);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator4.ClientID%>'), false);
}
}
</script>
</form>
</body>
</html>
|
|

August 8th, 2012, 04:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
I need update only the view of GridView when I use the filtering in my web page.
|
Ah, OK.
Still hard to say as you're not showing the relevant parts of this which are the SQL statements and the way they are built up.
Did you debug your SQL statement? Does it contain the relevant critera?
Imar
|
|

August 8th, 2012, 04:57 AM
|
|
Authorized User
|
|
Join Date: Aug 2012
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Thank you.
I don't have error in debug for SQL statement: all working also queries execute where conditions.
My first problem is in the javascript validator function... the validator working but I can not replace the error message in display for alert javascript.
When validation is failed I need to show the alert javascript and not error message in display and not refresh GridView.
Other problem is the refresh GridView when I use the filtering in my web page. When click on the:
Code:
<asp:ImageButton ID="Button1" ImageUrl="images/icon.gif" runat="server" OnClick="Button1_Click"
OnClientClick="javascript:InitValidators();return false;" />
The view of GridView not change, the problem is:
Code:
OnClientClick="javascript:InitValidators();return false;"
How to change to refresh the gridview with the values selected in filtering ?
|
|

August 8th, 2012, 05:02 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Code:
OnClientClick="javascript:InitValidators();return false;"
You're returning false, so your regular click casuing a postback never fires....
Imar
|
|

August 8th, 2012, 05:08 AM
|
|
Authorized User
|
|
Join Date: Aug 2012
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Imar
Code:
OnClientClick="javascript:InitValidators();return false;"
You're returning false, so your regular click casuing a postback never fires....
Imar
|
Ok, I tried this, but I have all ValidatorEnable true...
Code:
OnClientClick="javascript:InitValidators();"
This condition not working end of run:
Code:
<script type="text/javascript" language="javascript">
function InitValidators() {
var DateStart = document.getElementById('<%=DateStart.ClientID%>');
var DateEnd = document.getElementById('<%=DateEnd.ClientID%>')
var DateStart1 = document.getElementById('<%=DateStart1.ClientID%>');
var DateEnd1 = document.getElementById('<%=DateEnd1.ClientID%>')
if (DateStart.value == '' || DateEnd.value == '') {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator1.ClientID%>'), true);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator2.ClientID%>'), true);
}
else {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator1.ClientID%>'), false);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator2.ClientID%>'), false);
}
if (DateStart1.value == '' || DateEnd1.value == '') {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator3.ClientID%>'), true);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator4.ClientID%>'), true);
}
else {
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator3.ClientID%>'), false);
ValidatorEnable(document.getElementById('<%= RequiredFieldValidator4.ClientID%>'), false);
}
}
</script>
|
|

August 8th, 2012, 05:17 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I am sure but I completely lost. I have no idea what this means:
Quote:
|
Ok, I tried this, but I have all ValidatorEnable true...
|
nor this:
Quote:
|
This condition not working end of run:
|
I would trim down the page to the absolute minimum to reproduce and show the problem, and then post the full source code with a clear problem description. Otherwise, we'll just be running around in circles.
Cheers,
Imar
|
|
 |