Calling server-side function from client-side 
Author Message
 Calling server-side function from client-side

Hi,

I have a grid with text boxes for users to enter information.  They can enter up
to 6 items.  While they're entering search parameters (and before they click
the "Submit" button) there's one HTML box that triggers server-side code.  For
instance, after they enter data in one text box the onchange event will trigger a
server-side function.

I'm having trouble passing parameters to this function.  When I do so I get a
blank screen.  Also, I don't know how to return values.  If the item is found in
the recordset then I want to send an alert, otherwise, I don't want to.

The attached file contains the code and can be found below:

****************************************************

function txtDescription_onchange(i) { //i=1 to 6 and is set earlier
        var strID, var strFind, strStatus;

        //Get value of user input
        strID = document.thisForm.txtID(index).value;

        // Call GetStatus function to check status table
        strFind='<%GetStatus(strID)%>'; //adding parameter causes screen to go
blank

        // if item found in table then alert user that item is inactive
        strStatus='<%=Session('Status')%>';
        if (strStatus='true') {
                        alert('The item you have selected in active.');
        }

Quote:
}

//Here's the GetStatus function:

function GetStatus(strID) {

        Session('Status')='';

        // Search usp_FindStatus
        var strConn, rsStatus, cmdStatus;

        // open connection string
        strConn  = Server.CreateObject('ADODB.Connection')
        strConn.CursorLocation = 3      //adUseClient
        strConn.Open(blah, blah, blah)

        // open recordset
        rsStatus = Server.CreateObject("ADODB.Recordset")

        // Open a command object for a stored procedure
        // with one parameter
        cmdStatus = Server.CreateObject('ADODB.Command');
        cmdStatus.ActiveConnection = strConn
        cmdStatus.CommandText = 'usp_FindStatus'
        cmdStatus.CommandType = 4
        cmdStatus.Parameters.Refresh

        cmdStatus.Parameters(1) = strID //1-based

        rsStatus = cmdStatus.Execute()

        //if user input returned found in recordset then set session(&#8216;Status&#8217;) to
true
if (rsStatus.RecordCount>0) {
                Session(&#8216;Status&#8217;)=True;
        } else {
                Session(&#8216;Status&#8217;)=False;
        }

Quote:
}



Mon, 01 Dec 2003 04:49:01 GMT  
 Calling server-side function from client-side
this is all wrong you can't call a function on the server from the client
like this.
Submit strID through a from with a hidden field or something and let the asp
code check for it like so:
if(Request.Form('strID')>'')
    GetStatus(Request.Form('strID'))

Dade


Hi,

I have a grid with text boxes for users to enter information.  They can
enter up
to 6 items.  While they're entering search parameters (and before they click
the "Submit" button) there's one HTML box that triggers server-side code.
For
instance, after they enter data in one text box the onchange event will
trigger a
server-side function.

I'm having trouble passing parameters to this function.  When I do so I get
a
blank screen.  Also, I don't know how to return values.  If the item is
found in
the recordset then I want to send an alert, otherwise, I don't want to.

The attached file contains the code and can be found below:

****************************************************

function txtDescription_onchange(i) { //i=1 to 6 and is set earlier
var strID, var strFind, strStatus;

//Get value of user input
strID = document.thisForm.txtID(index).value;

// Call GetStatus function to check status table
strFind='<%GetStatus(strID)%>'; //adding parameter causes screen to go
blank

// if item found in table then alert user that item is inactive
strStatus='<%=Session('Status')%>';
if (strStatus='true') {
             alert('The item you have selected in active.');
        }

Quote:
}

//Here's the GetStatus function:

function GetStatus(strID) {

Session('Status')='';

// Search usp_FindStatus
var strConn, rsStatus, cmdStatus;

// open connection string
strConn  = Server.CreateObject('ADODB.Connection')
strConn.CursorLocation = 3 //adUseClient
strConn.Open(blah, blah, blah)

// open recordset
rsStatus = Server.CreateObject("ADODB.Recordset")

// Open a command object for a stored procedure
// with one parameter
cmdStatus = Server.CreateObject('ADODB.Command');
cmdStatus.ActiveConnection = strConn
cmdStatus.CommandText = 'usp_FindStatus'
cmdStatus.CommandType = 4
cmdStatus.Parameters.Refresh

cmdStatus.Parameters(1) = strID //1-based

rsStatus = cmdStatus.Execute()

//if user input returned found in recordset then set
session(&#8216;Status&#8217;) to
true
if (rsStatus.RecordCount>0) {
Session(&#8216;Status&#8217;)=True;

Quote:
} else {

Session(&#8216;Status&#8217;)=False;
Quote:
}
}



Mon, 01 Dec 2003 19:12:52 GMT  
 Calling server-side function from client-side
Thanks for your feedback!  Unfortunately I'm confused.

Currently in the ONCHANGE event of the text box a server component is called and
variables are passed.  The value returned automatically fills another textbox.  
So without clicking "Submit" the user's action (ONCHANGE) triggers server-side
code.  Variables are passed to the server component.

With my modification I also want to pass variables but instead of to another
server component to a stored procedure in a server-side function.

Following is the code that triggers the server component.  I want to add to the
ONCHANGE event of the txtID by also calling a stored procedure:

*******

function txtID_onchange(i)
//index is a 0-based array
var index=i-1;
var ds, strDescription, objOrder, strConn, strClass, strStyle;
        ds = new ActiveXObject("rds.Dataspace");
        objOrder = ds.createobject('bus_Order.Order', 'http://<%
=Request.ServerVariables("SERVER_NAME")%>');
        strClass = document.thisForm.txtID(index).value;
        strConn = '<%=Session("strConn")%>';
        strDescription = objOrder.GetItemDescription(strConn,strID)

*******

I understand, in your example, that once I get to the server-side that I should
run a function based on the user's input into "txtID".  But how is the server-
side code triggered?  You mentioned "submit strID through a form with a hidden
field".  How can I "submit" the form without forcing the user to click a button?

Thanks!

Lynn

Quote:
-----Original Message-----

this is all wrong you can't call a function on the server from the client
like this.
Submit strID through a from with a hidden field or something and let the asp
code check for it like so:
if(Request.Form('strID')>'')
    GetStatus(Request.Form('strID'))

Dade



Hi,

I have a grid with text boxes for users to enter information.  They can
enter up
to 6 items.  While they're entering search parameters (and before they click
the "Submit" button) there's one HTML box that triggers server-side code.
For
instance, after they enter data in one text box the onchange event will
trigger a
server-side function.

I'm having trouble passing parameters to this function.  When I do so I get
a
blank screen.  Also, I don't know how to return values.  If the item is
found in
the recordset then I want to send an alert, otherwise, I don't want to.

The attached file contains the code and can be found below:

****************************************************

function txtDescription_onchange(i) { //i=1 to 6 and is set earlier
var strID, var strFind, strStatus;

//Get value of user input
strID = document.thisForm.txtID(index).value;

// Call GetStatus function to check status table
strFind='<%GetStatus(strID)%>'; //adding parameter causes screen to go
blank

// if item found in table then alert user that item is inactive
strStatus='<%=Session('Status')%>';
if (strStatus='true') {
             alert('The item you have selected in active.');
        }
}

//Here's the GetStatus function:

function GetStatus(strID) {

Session('Status')='';

// Search usp_FindStatus
var strConn, rsStatus, cmdStatus;

// open connection string
strConn  = Server.CreateObject('ADODB.Connection')
strConn.CursorLocation = 3 //adUseClient
strConn.Open(blah, blah, blah)

// open recordset
rsStatus = Server.CreateObject("ADODB.Recordset")

// Open a command object for a stored procedure
// with one parameter
cmdStatus = Server.CreateObject('ADODB.Command');
cmdStatus.ActiveConnection = strConn
cmdStatus.CommandText = 'usp_FindStatus'
cmdStatus.CommandType = 4
cmdStatus.Parameters.Refresh

cmdStatus.Parameters(1) = strID //1-based

rsStatus = cmdStatus.Execute()

//if user input returned found in recordset then set
session(&#8216;Status&#8217;) to
true
if (rsStatus.RecordCount>0) {
Session(&#8216;Status&#8217;)=True;
} else {
Session(&#8216;Status&#8217;)=False;
}
}

.



Tue, 02 Dec 2003 01:02:34 GMT  
 Calling server-side function from client-side
if this is a client code you are showing me here below this component
(rds.Dataspace)
activates the Remote Data Service (rds) on the client machine not the
server, and his
rds object calls your servers database, as far as I know there has never
been any
other way then submitting the info to the server ( except making a link with
parameters)

Dade


Thanks for your feedback!  Unfortunately I'm confused.

Currently in the ONCHANGE event of the text box a server component is called
and
variables are passed.  The value returned automatically fills another
textbox.
So without clicking "Submit" the user's action (ONCHANGE) triggers
server-side
code.  Variables are passed to the server component.

With my modification I also want to pass variables but instead of to another
server component to a stored procedure in a server-side function.

Following is the code that triggers the server component.  I want to add to
the
ONCHANGE event of the txtID by also calling a stored procedure:

*******

function txtID_onchange(i)
//index is a 0-based array
var index=i-1;
var ds, strDescription, objOrder, strConn, strClass, strStyle;
ds = new ActiveXObject("rds.Dataspace");
objOrder = ds.createobject('bus_Order.Order', 'http://<%
=Request.ServerVariables("SERVER_NAME")%>');
strClass = document.thisForm.txtID(index).value;
strConn = '<%=Session("strConn")%>';
strDescription = objOrder.GetItemDescription(strConn,strID)

*******

I understand, in your example, that once I get to the server-side that I
should
run a function based on the user's input into "txtID".  But how is the
server-
side code triggered?  You mentioned "submit strID through a form with a
hidden
field".  How can I "submit" the form without forcing the user to click a
button?

Thanks!

Lynn

Quote:
-----Original Message-----

this is all wrong you can't call a function on the server from the client
like this.
Submit strID through a from with a hidden field or something and let the asp
code check for it like so:
if(Request.Form('strID')>'')
    GetStatus(Request.Form('strID'))

Dade



Hi,

I have a grid with text boxes for users to enter information.  They can
enter up
to 6 items.  While they're entering search parameters (and before they click
the "Submit" button) there's one HTML box that triggers server-side code.
For
instance, after they enter data in one text box the onchange event will
trigger a
server-side function.

I'm having trouble passing parameters to this function.  When I do so I get
a
blank screen.  Also, I don't know how to return values.  If the item is
found in
the recordset then I want to send an alert, otherwise, I don't want to.

The attached file contains the code and can be found below:

****************************************************

function txtDescription_onchange(i) { //i=1 to 6 and is set earlier
var strID, var strFind, strStatus;

//Get value of user input
strID = document.thisForm.txtID(index).value;

// Call GetStatus function to check status table
strFind='<%GetStatus(strID)%>'; //adding parameter causes screen to go
blank

// if item found in table then alert user that item is inactive
strStatus='<%=Session('Status')%>';
if (strStatus='true') {
             alert('The item you have selected in active.');
        }
}

//Here's the GetStatus function:

function GetStatus(strID) {

Session('Status')='';

// Search usp_FindStatus
var strConn, rsStatus, cmdStatus;

// open connection string
strConn  = Server.CreateObject('ADODB.Connection')
strConn.CursorLocation = 3 //adUseClient
strConn.Open(blah, blah, blah)

// open recordset
rsStatus = Server.CreateObject("ADODB.Recordset")

// Open a command object for a stored procedure
// with one parameter
cmdStatus = Server.CreateObject('ADODB.Command');
cmdStatus.ActiveConnection = strConn
cmdStatus.CommandText = 'usp_FindStatus'
cmdStatus.CommandType = 4
cmdStatus.Parameters.Refresh

cmdStatus.Parameters(1) = strID //1-based

rsStatus = cmdStatus.Execute()

//if user input returned found in recordset then set
session(&#8216;Status&#8217;) to
true
if (rsStatus.RecordCount>0) {
Session(&#8216;Status&#8217;)=True;
} else {
Session(&#8216;Status&#8217;)=False;
}
}

.



Tue, 02 Dec 2003 18:06:14 GMT  
 Calling server-side function from client-side


Fri, 19 Jun 1992 00:00:00 GMT  
 Calling server-side function from client-side
Yes, this is client-side code and these are design-time controls.  Could I also
do this code with straight HTML controls?  Do you suggest your way or this way or
does it matter?  (Eventually I would like to re-write this page using straight
HTML but I need to totally understand it before I do.)

Thanks Dade.

Lynn

Quote:
-----Original Message-----

Message%20unavailable



Tue, 02 Dec 2003 23:13:55 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Calling client-side javascript function from server-side vbscript

2. Client-side Subroutine calling Server-Side Subroutine

3. Calling client-side javascript from server-side vbscript

4. Calling server side from client side

5. Calling Server Side Script from Client Side Script

6. Call Server Side Script From Client Side Script

7. Help- Client script calling server side function

8. Calling Server Side JScript from Server Side VBScript

9. store server-side array in client side

10. pass server side vbscript to client side javascript

11. Client side VS server side

12. Client Side + Server Side Scripts

 

 
Powered by phpBB® Forum Software