?
Solved

How  remote scripting is  done in ASP??

Posted on 2003-02-20
7
Medium Priority
?
250 Views
Last Modified: 2010-03-17
Hi guys..
Thanks in advance, to lokk at it...
The problem defined is, i want to populate, a combobox in the clientside, accoring to the input of the other combobox, and must be handled at the server side, for example..
i have two compo boxes, one having the country name and the other having the stae of it, when i changed the coutny combo entry in to the other one, then the request must be automatically gone to the server and and must return the same page with the the state cobmo box having the state's of the selected country
pls give me the code if u can..
once more thanks in advance...
0
Comment
Question by:anuragvelekkattu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 1

Accepted Solution

by:
NicolNghia earned 136 total points
ID: 8015605
Hi anuragvelekkattu,

Below is an idea that can help you to do as above requirement:
- When event 'onchange' happen, you can submit your form that contain selected Country to the same asp page.
- In the ASP page, to fill data for the State combobox, you check the Country combobox, if no Country is selected
you can fill all states (or non) in the State combobox. Otherwise, you query all States of the seleted country and fill them into the State combobox.
And the same page will be returned.

However, I think the way you want to do is not nice. Because, the users have to wait so much time whenever they select other country (connect to server).
I did use other way for that:
- When the page is returned, an XML that contains all countrys and states is included in the page.
E.g.:

<CountryState>
<Country>
     <Name>Country1<Name>
     <ID>CountryID1</ID>
     <State>
          <Name>State11</Name>
          <ID>StateID11</ID>
     </State>
     <State>
          <Name>State12</Name>
          <ID>StateID12</ID>
     </State>
</Country>
<Country>
     <Name>Country2<Name>
     <ID>CountryID2</ID>
     <State>
          <Name>State21</Name>
          <ID>StateID21</ID>
     </State>
     <State>
          <Name>State22</Name>
          <ID>StateID22</ID>
     </State>
<Country>
</CountryState>

- And use XML DSO to manipulate the data easily by script code.
(The XML DSO is supported by Microsoft Internet Explorer versions 4 and later.)

Good luck,
0
 
LVL 1

Assisted Solution

by:ach_maverick
ach_maverick earned 132 total points
ID: 8410707
you must be having a database with country relating to states field. when you click the first country in the combo box use "onchange" method and call and submit the form making a simple javascript function. when the form is sumbmitted you can get the value of the combo box by request method and then use it to run a query on your table with the country field and can populate your combo box with it.
0
 

Assisted Solution

by:saaketham
saaketham earned 132 total points
ID: 8432062
Hi Anurag,

When you say that you want the request to be handled at the server side, I assume you mean you wish to use Remote Scripting (RS). This is extremely useful because you can populate the control (such as your combo box) alone and not have to refresh the entire page.

What you need to do:
--------------------
1. Enable and set as default, Microsoft Java Virtual Machine on the server

2. Download the files needed for RS from the web (three files are needed - rs.htm, rs.asp, rsproxy.class) - http://download.microsoft.com/download/asp/Install/1.0b/W982KMeXP/EN-US/rs10ben.exe

3. Install RS by running above downloaded exe

4. Create 2 files, one the .asp page that you are going to use as an object and a .htm page that will contain the Javascript that will call this page and its functions.

Here's the code for one of my earlier RS pages:

A. MyASP.ASP
------------
<%@ Language=VBScript %>
<% RSDispatch %>

<!--#INCLUDE FILE="../rs.asp"-->
<script language="JavaScript" runat="server">
 function MainMethod()
 {
   this.GetStates = Function('Country','return Get_States  
                    Country)')
   // Add as many functions as you need publicly exposed
 }
 public_description = new MainMethod();
</script>

<script language="VBScript" runat="server">
Function Get_States(Country)
   Dim Conn, rsCon, Names
   Set Conn = server.createobject("ADODB.Connection")
   Set rsCon = server.createobject("ADODB.Recordset")
   Conn.open "provider=SQLOLEDB;Data Source=
             (local);Initial Catalog =  
             <DATABASENAME>;UID=<USERNAME>;PWD=<PASSWORD>"

   rsCon.Open ("SELECT StateName As Name FROM dbo.States
               WHERE Country = '" & Country & "' ORDER BY
               Name", Conn)
   While Not rsCon.EOF
      ' Use an array instead of |-delimited string
      Names = Names & rsCon("Name") & "|"
      rsCon.MoveNext
   Wend
 
   rsCon.Close
   Conn.Close
         
   Set rsCon = Nothing
   Set Conn = Nothing
     
   Get_States = Names
 End Function
</script>

B. MyHTM.HTM
------------
<html>
<body>
<script language="JavaScript" src="../rs.htm"></script>
<script language="JavaScript">RSEnableRemoteScripting("..");</script>

<script>
function GetStates()
{
  // Clear current entries and add a default option
  document.frmWorld.States.length = 0
  document.frmWorld.States.options[0] = new Option()
  document.frmWorld.States.options[0].text="Select State"
 
  var objRS = RSGetASPObject("MyASP.asp");
  var objResult = objRS.GetStates();
  var strNames = objResult.return_value;
                   
  // If you use an array instead of |-delimited string,  
  // you wont have to use Split. And it saves a lot of time

  var arrStates = strNames.split("|");
  for(i = 0; i < arrStates.length-1; i++)
  {
    document.frmWorld.States.options[i] = new Option();
    document.frmWorld.States.options[i].text = arrStates
                                                [i];
  }
  strNames = ""
}
               
</script>

<form name="frmWorld" action="#" method="post" ID="Form1">
Countries:
  <select id="Countries" name="Countries"
   onChange="GetStates()">
    <option selected>Select a Country</option>
  </select>

  States:
  <select id="States" name="States">
    <option selected>Select a State</option>
  </select>
</form>
</body>
</html>

To populate the list of countries, you can create another function in MyASP.ASP that you can then call in the <Body OnLoad="GetCountries">.

The key things to get this to work are the relative paths of the _ScriptLibrary folder where the RS files needed will be installed. That is a different topic altogether. But if you cant get this working anytime soon, post again as a new question and I will try to guide you through it.
0
 

Expert Comment

by:saaketham
ID: 8432088
Anurag,

I missed something in the code above. I actually modified one of my pages to suit your needs, but overlooked the fact that I wasn't passing in the Country parameter to the function. Here's how you can do that in MyHTM.HTM.

function GetStates()
{
 // Clear current entries and add a default option
 document.frmWorld.States.length = 0
 document.frmWorld.States.options[0] = new Option()
 document.frmWorld.States.options[0].text="Select State"
 
 // EXTRA LINES ADDED
 var CountryIndex =
     document.frmWorld.Countries.selectedIndex;
 var Country = document.frmWorld.Countries.option
     [CountryIndex].text
 
 // END EXTRA LINES

  var objRS = RSGetASPObject("MyASP.asp");
  var objResult = objRS.GetStates(Country);
  var strNames = objResult.return_value;
                   
 // If you use an array instead of |-delimited string,  
 // you wont have to use Split. And it saves a lot of time

 var arrStates = strNames.split("|");
 for(i = 0; i < arrStates.length-1; i++)
 {
   document.frmWorld.States.options[i] = new Option();
   document.frmWorld.States.options[i].text = arrStates
                                               [i];
 }
 strNames = ""
}
0
 

Expert Comment

by:saaketham
ID: 8432090
Anurag,

I missed something in the code above. I actually modified one of my pages to suit your needs, but overlooked the fact that I wasn't passing in the Country parameter to the function. Here's how you can do that in MyHTM.HTM.

function GetStates()
{
 // Clear current entries and add a default option
 document.frmWorld.States.length = 0
 document.frmWorld.States.options[0] = new Option()
 document.frmWorld.States.options[0].text="Select State"
 
 // EXTRA LINES ADDED
 var CountryIndex =
     document.frmWorld.Countries.selectedIndex;
 var Country = document.frmWorld.Countries.option
     [CountryIndex].text
 
 // END EXTRA LINES

  var objRS = RSGetASPObject("MyASP.asp");
  var objResult = objRS.GetStates(Country);
  var strNames = objResult.return_value;
                   
 // If you use an array instead of |-delimited string,  
 // you wont have to use Split. And it saves a lot of time

 var arrStates = strNames.split("|");
 for(i = 0; i < arrStates.length-1; i++)
 {
   document.frmWorld.States.options[i] = new Option();
   document.frmWorld.States.options[i].text = arrStates
                                               [i];
 }
 strNames = ""
}
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert websphere application server default chained Certificates from 1024 to 2048 keysize or higher size and also you can change signatureAlgorithm . Please make sure Websphere Application Server fixpack 7.0.0.23 or Above. The following steps a…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question