Hi,
Below is the Javascript function that am trying to call from asp:Button
control.
<script language="javascript">
function ValidateDate(fromDate,toDate)
{
var fromDate=new Date();
var toDate=new Date();
var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );
alert(diffDate);
if( diffDate < 0 )
{
alert( "The start date cannot be after the end date!")
return false;
}
if( diffDate > 30 )
{
alert( "Please enter dates less than 31 days apart" )
return false;
}
return true; //allow submit
}
</script>
In code-behind am calling the function like as below:
btnSubmit.Attributes.Add("onClick"," return ValidateDate(" +
txtFromDate.Text.ToString() + "," + txtToDate.Text.ToString() + ");");
But if start entering the dates,it submits the page as it takes both
datee as current dates.Please let me know the reason.
Thanks,
VishnuTry this
btnSubmit.Attributes.Add("onClick"," return
ValidateDate(document.GetElementById('" +
txtFromDate.ClentId() + ').Value",document.GetElementById('" +
txtToDate.ClentId()+ "'));");
settyv@.gmail.com wrote:
> Hi,
> Below is the Javascript function that am trying to call from asp:Button
> control.
> <script language="javascript">
> function ValidateDate(fromDate,toDate)
> {
> var fromDate=new Date();
> var toDate=new Date();
> var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );
> alert(diffDate);
> if( diffDate < 0 )
> {
> alert( "The start date cannot be after the end date!")
> return false;
> }
> if( diffDate > 30 )
> {
> alert( "Please enter dates less than 31 days apart" )
> return false;
> }
> return true; //allow submit
> }
> </script>
>
> In code-behind am calling the function like as below:
> btnSubmit.Attributes.Add("onClick"," return ValidateDate(" +
> txtFromDate.Text.ToString() + "," + txtToDate.Text.ToString() + ");");
>
> But if start entering the dates,it submits the page as it takes both
> datee as current dates.Please let me know the reason.
> Thanks,
> Vishnu
Hi,
It is not working .it is telling script error.Here is the HTML created
after the postback.Everything is fine.But i dont know why it is telling
error.
Microsoft JScript runtime error: 'document.GetElementById.txtFromDate'
is null or not an object
<TR vAlign="top">
<TD colSpan="4" height="25"></TD>
<TD><input type="submit" name="btnSubmit" value="Submit"
id="btnSubmit" onClick="return
ValidateDate(document.getElementById["txtFromDate"].Value,document.getElemen
tById["txtToDate"].Value);"
/></TD>
</TR>
Please let me know how can i solve this.
Thanks,
Vishnu
rampabbaraju@.gmail.com wrote:
> Try this
> btnSubmit.Attributes.Add("onClick"," return
> ValidateDate(document.GetElementById('" +
> txtFromDate.ClentId() + ').Value",document.GetElementById('" +
> txtToDate.ClentId()+ "'));");
>
> settyv@.gmail.com wrote:
Show us more code (espacially text boxes declaration)
--
Milosz Skalecki
MCP, MCAD
"settyv@.gmail.com" wrote:
> Hi,
> It is not working .it is telling script error.Here is the HTML created
> after the postback.Everything is fine.But i dont know why it is telling
> error.
> Microsoft JScript runtime error: 'document.GetElementById.txtFromDate'
> is null or not an object
> <TR vAlign="top">
> <TD colSpan="4" height="25"></TD>
> <TD><input type="submit" name="btnSubmit" value="Submit"
> id="btnSubmit" onClick="return
> ValidateDate(document.getElementById["txtFromDate"].Value,document.getElem
entById["txtToDate"].Value);"
> /></TD>
> </TR>
> Please let me know how can i solve this.
>
> Thanks,
> Vishnu
> rampabbaraju@.gmail.com wrote:
>
Hi,
Here is the ASPX code.
<body ms_positioning="gridlayout">
<TABLE height="471" cellSpacing="0" cellPadding="0" width="174"
border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD width="174" height="471">
<form id="form1" runat="server">
<TABLE height="157" cellSpacing="0" cellPadding="0" width="459"
border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD colSpan="3" height="1"></TD>
<TD colSpan="2" rowSpan="2"><asp:textbox id="txtToDate"
runat="server"></asp:textbox></TD>
</TR>
<TR vAlign="top">
<TD height="38"></TD>
<TD colSpan="2"><asp:label id="lblFDate" runat="server"
Width="87px">From Date:</asp:label></TD>
</TR>
<TR vAlign="top">
<TD colSpan="2" height="1"></TD>
<TD colSpan="3" rowSpan="2"><asp:textbox id="txtFromDate"
runat="server"></asp:textbox></TD>
</TR>
<TR vAlign="top">
<TD height="41"></TD>
<TD><asp:label id="lblTDate" runat="server" Width="83px">To
Date:</asp:label></TD>
</TR>
<TR vAlign="top">
<TD colSpan="4" height="25"></TD>
<TD><asp:button id="btnSubmit" runat="server"
Text="Submit"></asp:button></TD>
</TR>
</TABLE>
</form>
</TD>
</TR>
</TABLE>
</body>
And am trying to call the javascript that i sent earlier in code-behind
as shown below:
btnSubmit.Attributes.Add("onClick","return
ValidateDate(document.form1.elements['" + txtFromDate.ClientID +
"'].value,document.form1.elements['"
+ txtToDate.ClientID + "'].value);");
Now the problem is that am not able to see alert msg saying that the
difference is 0 ,which takes both dates as current date and it returns
the difference as 0. Please let me know how can i solve this issue.
Thanks,
Vishnu
Milosz Skalecki wrote:
> Show us more code (espacially text boxes declaration)
> --
> Milosz Skalecki
> MCP, MCAD
>
> "settyv@.gmail.com" wrote:
>
Wednesday, March 21, 2012
Please help me how to call this Javascript
Labels:
asp,
aspbuttoncontrol,
below,
call,
function,
gtfunction,
javascript,
language,
ltscript,
net
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment