Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Saturday, March 24, 2012

Please help ! Problem about HttpWebRequest - GetResponse()

Hi all,
I have problem when I use HttpWebRequest and take long time to call to my
service server. If at that time there are many request comes in
semultaneous, I will get this exception
System.Net.WebException: The underlying connection was closed: The request
was canceled. --> System.IO.IOException: Unable to read data from the
transport connection. --> System.ObjectDisposedException: Cannot access a
disposed object named "System.Net.TlsStream".
Object name: "System.Net.TlsStream".
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
at System.Net.TlsStream.AsyncReceiveComplete(IAsyncResult result)
-- End of inner exception stack trace --
at System.Net.TlsStream.EndRead(IAsyncResult asyncResult)
at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
-- End of inner exception stack trace --
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at MFEC.DealerServices.Service.PaymentGateway.CallPaymentGateway(String
serviceName, GeneralParameterCollection inputParam)
Does anybody know how to solve this problem ?Have you seen this?
http://support.microsoft.com/defaul...kb;en-us;884537
- slightly different scenario, but you might be hitting the same bug.
Scott
http://www.OdeToCode.com/blogs/scott/
On Fri, 22 Apr 2005 10:10:02 GMT, "japslam japslam via
webservertalk.com" <forum@.nospam.webservertalk.com> wrote:

>Hi all,
>I have problem when I use HttpWebRequest and take long time to call to my
>service server. If at that time there are many request comes in
>semultaneous, I will get this exception
>System.Net.WebException: The underlying connection was closed: The request
>was canceled. --> System.IO.IOException: Unable to read data from the
>transport connection. --> System.ObjectDisposedException: Cannot access a
>disposed object named "System.Net.TlsStream".
>Object name: "System.Net.TlsStream".
> at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
> at System.Net.TlsStream.AsyncReceiveComplete(IAsyncResult result)
> -- End of inner exception stack trace --
> at System.Net.TlsStream.EndRead(IAsyncResult asyncResult)
> at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
> -- End of inner exception stack trace --
> at System.Net.HttpWebRequest.CheckFinalStatus()
> at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
> at System.Net.HttpWebRequest.GetResponse()
> at MFEC.DealerServices.Service.PaymentGateway.CallPaymentGateway(String
>serviceName, GeneralParameterCollection inputParam)
>
>Does anybody know how to solve this problem ?

Please help ! Problem about HttpWebRequest - GetResponse()

Hi all,

I have problem when I use HttpWebRequest and take long time to call to my
service server. If at that time there are many request comes in
semultaneous, I will get this exception

System.Net.WebException: The underlying connection was closed: The request
was canceled. --> System.IO.IOException: Unable to read data from the
transport connection. --> System.ObjectDisposedException: Cannot access a
disposed object named "System.Net.TlsStream".
Object name: "System.Net.TlsStream".
at System.Net.Sockets.NetworkStream.EndRead(IAsyncRes ult asyncResult)
at System.Net.TlsStream.AsyncReceiveComplete(IAsyncRe sult result)
-- End of inner exception stack trace --
at System.Net.TlsStream.EndRead(IAsyncResult asyncResult)
at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
-- End of inner exception stack trace --
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at MFEC.DealerServices.Service.PaymentGateway.CallPay mentGateway(String
serviceName, GeneralParameterCollection inputParam)

Does anybody know how to solve this problem ?Hi,

The problem is that your proxy is not allowing the webrequest.
Do one thing create a webproxy object with your proxy name and port and
bind it to webrequest like this.

// True is to by pass proxy for local
WebProxy proxy = new WebProxy(name:port, true);

// suppose req is HttpWebRequest object
req.Proxy = proxy;

and then user req.getResponse method to get the response.

Regards,
Angrez
Hi singh_angrez,

Thank you for your suggestion. But I can test it in next 2 day after this
weekend. After I try I will report the result again if it can solve my
problem or not

Thank you very much

Jap.
Hi singh_angrez,

Before I try your suggestion. I wanna show you about my code.
And my server architecture is like this

Web server --httprequest call to --> My service server

Actually, If my service server reponse the result to me in a short time,
everything is ok..no exception. But anytime my service server take long
time to process and send me the result.. at that time if there are many
requests from web server call to my service server, I got that exception
until my service server have a good response.

This is my code now. May be my code is not correct about HttpWebRequest
property.

//==== set ssl connection ==
ServicePointManager.CertificatePolicy = new MyPolicy();

HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create
(PAYMENTGATEWAY_URL+strParam.ToString());
objRequest.Method = "GET";

//==== add new code ==
objRequest.KeepAlive = false;
objRequest.ProtocolVersion=HttpVersion.Version10;
objRequest.Proxy = System.Net.WebProxy.GetDefaultProxy(); // I use
default proxy which work well in normal time.
objRequest.AllowAutoRedirect=true;
objRequest.MaximumAutomaticRedirections=10;
objRequest.Timeout = (int) new TimeSpan(0,0,HTTPTIMEOUT)
..TotalMilliseconds; // ,HTTPTIMEOUT = 300
objRequest.UserAgent="Mozilla/3.0 (compatible; My Browser/1.0)";
//==== add new code ==

string str = null;
HttpWebResponse objResponse;
StreamReader sr = null;
try
{
objResponse = (HttpWebResponse)objRequest.GetResponse();

}
catch( Exception e)
{
EventMgmt.EventExceptionMsg("Payment Gateway-GetResponse() =>
"+e.ToString(), @."\DataAccess\PGWException");

throw new ServiceException("PGW001","HOST_UNREACHABLE",e);
}

try
{
sr = new StreamReader(objResponse.GetResponseStream());
str = sr.ReadToEnd().Replace('\n'.ToString(),"").Replace('\t'.ToString()
,"").Replace('&'.ToString(),"");
}
catch( Exception e)
{
EventMgmt.EventExceptionMsg("Payment Gateway-ReadResponseStream() =>
"+e.ToString(), @."\DataAccess\PGWException");

throw new ServiceException("PGW003","READ_STREAM_ERROR",e);
}
finally
{
if( sr != null)
sr.Close();
objResponse.Close();
}

Thank you,

Jap.
Have you seen this?
http://support.microsoft.com/defaul...kb;en-us;884537

- slightly different scenario, but you might be hitting the same bug.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 22 Apr 2005 10:10:02 GMT, "japslam japslam via
DotNetMonster.com" <forum@.nospam.DotNetMonster.com> wrote:

>Hi all,
>I have problem when I use HttpWebRequest and take long time to call to my
>service server. If at that time there are many request comes in
>semultaneous, I will get this exception
>System.Net.WebException: The underlying connection was closed: The request
>was canceled. --> System.IO.IOException: Unable to read data from the
>transport connection. --> System.ObjectDisposedException: Cannot access a
>disposed object named "System.Net.TlsStream".
>Object name: "System.Net.TlsStream".
> at System.Net.Sockets.NetworkStream.EndRead(IAsyncRes ult asyncResult)
> at System.Net.TlsStream.AsyncReceiveComplete(IAsyncRe sult result)
> -- End of inner exception stack trace --
> at System.Net.TlsStream.EndRead(IAsyncResult asyncResult)
> at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
> -- End of inner exception stack trace --
> at System.Net.HttpWebRequest.CheckFinalStatus()
> at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
> at System.Net.HttpWebRequest.GetResponse()
> at MFEC.DealerServices.Service.PaymentGateway.CallPay mentGateway(String
>serviceName, GeneralParameterCollection inputParam)
>
>Does anybody know how to solve this problem ?
the default setting for webclient is to only allow two connections to a
remote server. if you calls are slow, and they stack up, you will have
timeout problems. also you could hit your max thread pool sizes.

try upping the number of connections.
(httpRequest.ServicePoint.ConnectionLimit)

-- bruce (sqlwork.com)

"japslam japslam via DotNetMonster.com" <forum@.DotNetMonster.com> wrote in
message news:1b2e8e50a4a5493bbb9004d9c3d2c1f0@.DotNetMonste r.com...
> Hi singh_angrez,
>
> Before I try your suggestion. I wanna show you about my code.
> And my server architecture is like this
> Web server --httprequest call to --> My service server
> Actually, If my service server reponse the result to me in a short time,
> everything is ok..no exception. But anytime my service server take long
> time to process and send me the result.. at that time if there are many
> requests from web server call to my service server, I got that exception
> until my service server have a good response.
> This is my code now. May be my code is not correct about HttpWebRequest
> property.
>
> //==== set ssl connection ==
> ServicePointManager.CertificatePolicy = new MyPolicy();
> HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create
> (PAYMENTGATEWAY_URL+strParam.ToString());
> objRequest.Method = "GET";
> //==== add new code ==
> objRequest.KeepAlive = false;
> objRequest.ProtocolVersion=HttpVersion.Version10;
> objRequest.Proxy = System.Net.WebProxy.GetDefaultProxy(); // I use
> default proxy which work well in normal time.
> objRequest.AllowAutoRedirect=true;
> objRequest.MaximumAutomaticRedirections=10;
> objRequest.Timeout = (int) new TimeSpan(0,0,HTTPTIMEOUT)
> .TotalMilliseconds; // ,HTTPTIMEOUT = 300
> objRequest.UserAgent="Mozilla/3.0 (compatible; My Browser/1.0)";
> //==== add new code ==
> string str = null;
> HttpWebResponse objResponse;
> StreamReader sr = null;
> try
> {
> objResponse = (HttpWebResponse)objRequest.GetResponse();
> }
> catch( Exception e)
> {
> EventMgmt.EventExceptionMsg("Payment Gateway-GetResponse() =>
> "+e.ToString(), @."\DataAccess\PGWException");
> throw new ServiceException("PGW001","HOST_UNREACHABLE",e);
> }
> try
> {
> sr = new StreamReader(objResponse.GetResponseStream());
> str = sr.ReadToEnd().Replace('\n'.ToString(),"").Replace('\t'.ToString()
> ,"").Replace('&'.ToString(),"");
> }
> catch( Exception e)
> {
> EventMgmt.EventExceptionMsg("Payment Gateway-ReadResponseStream() =>
> "+e.ToString(), @."\DataAccess\PGWException");
> throw new ServiceException("PGW003","READ_STREAM_ERROR",e);
> }
> finally
> {
> if( sr != null)
> sr.Close();
> objResponse.Close();
> }
>
> Thank you,
> Jap.

Please help how to call stored procedure from asp.net code

Please help, first time trying to use the stored procedure.

Can you please modify my code below which is in asp.net to insert the record's in table(tbl_labels), i don't have not problem in inserting records, but i want to use my stored procedure to insert the record. Please help I never used a stored procedure.

**********


CREATE PROCEDURE sp_insert_label
(
@dotnet.itags.org.engl nvarchar,
@dotnet.itags.org.espl nvarchar,
@dotnet.itags.org.frlbl nvarchar,
@dotnet.itags.org.gerlbl nvarchar
)
AS
INSERT INTO tbl_labels
(
eng_lbl,
esp_lbl,
fr_lbl,
ger_lbl
)
VALUES
(
@dotnet.itags.org.engl,
@dotnet.itags.org.espl,
@dotnet.itags.org.frlbl,
@dotnet.itags.org.gerlbl
)
GO

********** the following is my asp.net code***

Sub Addlabel_Click(Sender As Object, E As EventArgs)
Page.Validate()
If Not Page.IsValid
Return
End If

Dim DS As DataSet
Dim MyCommand As SqlCommand
Dim InsertCmd As String = "insert into tbl_labels(eng_lbl, esp_lbl, " & _
"fr_lbl, ger_lbl) values " & _
"(@dotnet.itags.org.engl, @dotnet.itags.org.espn, @dotnet.itags.org.fren, @dotnet.itags.org.german)"

MyCommand = New SqlCommand(InsertCmd, MyConnection)

MyCommand.Parameters.Add( "@dotnet.itags.org.engl", eng_lbl.Value )
MyCommand.Parameters.Add( "@dotnet.itags.org.espn", esp_lbl.Value )
MyCommand.Parameters.Add( "@dotnet.itags.org.fren", fr_lbl.Value )
MyCommand.Parameters.Add( "@dotnet.itags.org.german", ger_lbl.Value )

MyCommand.Connection.Open()

Try
MyCommand.ExecuteNonQuery()
Message.InnerHtml = "Label Added Successfully to Dictionary.<br>" '& InsertCmd.ToString()
ger_lbl.Value = ""
fr_lbl.Value = ""
esp_lbl.Value = ""
eng_lbl.Value = ""

Catch Exp As SQLException
If Exp.Number = 2627
Message.InnerHtml = "ERROR: A record already exists with the " & _
"same primary key"
Else
Message.InnerHtml = "ERROR: Could not add record, please ensure " & _
"the fields are correctly filled out"
End If
Message.Style("color") = "red"
End Try

MyCommand.Connection.Close()
BindGrid()
End Sub

Hi,

Dim DS As DataSet

Dim MyCommand As SqlCommand

Dim pmEngl, pmEspn, pmFren, pmGerman As SqlParameter = New SqlParameter()

MyCommand = New SqlCommand("sp_insert_label", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure;

pmEngl = MyCommand.Parameters.Add( "@.engl", eng_lbl.Value )

pmEspn = MyCommand.Parameters.Add( "@.espn", esp_lbl.Value )

pmFren = MyCommand.Parameters.Add( "@.fren", fr_lbl.Value )

pmGerman = MyCommand.Parameters.Add( "@.german", ger_lbl.Value )

MyCommand.Connection.Open()

Try

MyCommand.ExecuteNonQuery()

Message.InnerHtml = "Label Added Successfully to Dictionary.<br>" '& InsertCmd.ToString()

ger_lbl.Value = ""

fr_lbl.Value = ""

esp_lbl.Value = ""

eng_lbl.Value = ""

hope it helps.
You can add parameters to stored procedures in different ways:

One of the useful way is:

myCommand.Parameters.Add(new SqlParameters("@.ParameterName",SqlDbType.nvarchar,50));
Thank you very much for your help Harish.

Wednesday, March 21, 2012

Please help me how to call this Javascript

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:
>

Please help me how to call this Javascript

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:

Quote:

Originally Posted by

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.getElementById["txtToDate"].Value);"
/></TD>
</TR>

Please let me know how can i solve this.

Thanks,
Vishnu

rampabbaraju@.gmail.com wrote:

Quote:

Originally Posted by

Try this
>
btnSubmit.Attributes.Add("onClick"," return
ValidateDate(document.GetElementById('" +
txtFromDate.ClentId() + ').Value",document.GetElementById('" +
txtToDate.ClentId()+ "'));");
>
>
>
settyv@.gmail.com wrote:

Quote:

Originally Posted by

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


Show us more code (espacially text boxes declaration)
--
Milosz Skalecki
MCP, MCAD

"settyv@.gmail.com" wrote:

Quote:

Originally Posted by

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.getElementById["txtToDate"].Value);"
/></TD>
</TR>
>
Please let me know how can i solve this.
>
>
Thanks,
Vishnu
>
rampabbaraju@.gmail.com wrote:

Quote:

Originally Posted by

Try this

btnSubmit.Attributes.Add("onClick"," return
ValidateDate(document.GetElementById('" +
txtFromDate.ClentId() + ').Value",document.GetElementById('" +
txtToDate.ClentId()+ "'));");

settyv@.gmail.com wrote:

Quote:

Originally Posted by

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,

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:

Quote:

Originally Posted by

Show us more code (espacially text boxes declaration)
--
Milosz Skalecki
MCP, MCAD
>
>
"settyv@.gmail.com" wrote:
>

Quote:

Originally Posted by

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.getElementById["txtToDate"].Value);"
/></TD>
</TR>

Please let me know how can i solve this.

Thanks,
Vishnu

rampabbaraju@.gmail.com wrote:

Quote:

Originally Posted by

Try 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



You're assigning both dates to current date:
fromDate = new Date();
toDate = new Date();
that's why you always get 0 in difference.

it should look like this:
-- begin javascript code --

function ValidateDate(fromDateStr,toDateStr)
{

var fromDate = new Date(fromDateStr) ;
var toDate = new Date(toDateStr);
var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );

alert(fromDate.toGMTString() + "\n" + toDate.toGMTString() + "\n" +
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
}

-- end javascript code --

and the Page_Load in code behind:

-- begin c# code --

btnSubmit.Attributes.Add("onClick", String.Format("return
ValidateDate(document.getElementById('{0}').value,
document.getElementById('{1}').value);",
txtFromDate.ClientID , txtToDate.ClientID));
-- end c# code --

Before you start working with dates in javascript please familirize yourself
with potential problems since date strings are always ambiguous, (i.e. you
should use
new Date (year, month [, date [, hours [, minutes [, seconds [, ms ]]]]])

hope this helps

--
Milosz Skalecki
MCP, MCAD

"settyv@.gmail.com" wrote:

Quote:

Originally Posted by

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:

Quote:

Originally Posted by

Show us more code (espacially text boxes declaration)
--
Milosz Skalecki
MCP, MCAD

"settyv@.gmail.com" wrote:

Quote:

Originally Posted by

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.getElementById["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:
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
>
>


>
>

Friday, March 16, 2012

please help this one is simple

I have some code stored in a file called functions.vb I want to be able to call methods in this class from anywhere in the project, for example functions.GetCookie("member_id").

I know how to do it if i compile it, make it a dll file and make it a reference, bu I do not want to do this because i want to beable to edit the code at anytime for some reason i cannot figure out how to accompish this. Seems like it should be very simple?Make a public class named "functions" and all of the methods you want to call "Shared", then include the functions.vb file in the project you want to call them from.

This will allow you call any shared method using the class name . method name from any place in the project.
right now i have functions in a . dll file and i am able to at the top of my code write:

Imports CoreFile.functions

and be able to call methods of the functions class without typing:
CoreFile.functions.GetCookie()

I can just simpley type GetCookie() it seems to me that the Import statement at the top of the code only works with references. is there a way around this? am i doing somthing wrong?

I want to be able to import my functions.vb class

Thanks.
it IS really simple:

if you want to be able to modify your code behind at any time and not have it as a dll then all you need to do is include this at the top of your aspx page:


<%@. Page Inherits="myCodeBehind" src="http://pics.10026.com/?src=myCodeBehind.vb" %>

with this line at the top of your aspx page, you can access any of the functions in your vb file without having it in dll form. just remember to change myCodeBehind.vb to whateveer your codebind.vb page is called.
If you change GetCookie() or any other function inside your functions.vb class you have to re-compile the class and re-compile your application referencing that class (if you want it to access the newly modified functions).

I keep two copies of visual studio open at all times. One has my web application and the other has my functions. Recompile functions, recompile app and now app can access any new functions and the modified functions.

If you think about "how" it works it makes sense. My app references "functions.vb" which is compiled into a DLL and copied into my apps folder. When I re-compile "functions.vb" the newly compiled DLL is still located in it's own base folder. It's not until I re-compile my app that it brings over the new copy of the DLL.
yes that works for a .aspx page but what if i am calling the method from other classes as described above. I can write "Imports CoreFile.functions " at the top of the class
this allows me to call methods of my functions class without writing CoreFile.functions.GetCookie(). Instead I can just write GetCookie() and it recognizes it as CoreFile.functions.GetCookie() is there a way to import a file that is not in references. I want to be able to do something to the effect of "Imports functions.vb" right now it is set as "Imports CoreFile.functions " where CoreFile is a dll defined in references.