Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional 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
 
Old January 28th, 2005, 12:13 AM
Authorized User
 
Join Date: Dec 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jaywhy13 Send a message via Yahoo to jaywhy13
Default Communicate with server durin run time

I know that ASP is like a server side language and all but is there like a way that you can communicate with the server after the page is loaded to get data like application data Without refreshing or reloading the page?

And is so... how risky is sumin like this? ;)

Jay
Knowledge is power and igorance is bliss... which is more exciting?
__________________
I\'m gonna download the internet if its the last thing I do....
Until the algorithm is finished u must prepared to bow down and worship me (or my grave).... i figured i\'ll b finished b4 the latter!
 
Old January 28th, 2005, 12:38 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

There are two methods for refreshing parts of web page. Unfortunately both these methods work only in IE 5.0 (and above) only.

1) Using scriptlets. The following link gives more info on this.

http://www.codeproject.com/html/topten.asp

2) using XML. This method basically involves submitting an XML through Javascript to a web page and getting the response as another XML. Then the response XML need to be parsed and results shown in page.

Here is a sample script for this. This will fetch the related fabric types when a select box entry containing fabric categories is changed.

The page :
Code:
<html>
<head>
    <title>Untitled</title>
    <script language="JavaScript1.2" type="text/javascript">
        function func_retrieve_fabric_types()
        {
            var str_xml="";
            //alert(document.frm_test.cbo_fabric_categories.options[document.frm_test.cbo_fabric_categories.selectedIndex].value);
            if(!((document.frm_test.cbo_fabric_categories.options[document.frm_test.cbo_fabric_categories.selectedIndex].value)==""))
            {
                str_xml+="<xml_to_be_submitted><request_xml><fabric_cat_id>"+document.frm_test.cbo_fabric_categories.options[document.frm_test.cbo_fabric_categories.selectedIndex].value+"</fabric_cat_id></request_xml></xml_to_be_submitted>";
                var obj_http=new ActiveXObject("Microsoft.XMLHTTP");
                var str_url="testfb.asp";
                var str_http_method="post";
                obj_http.open(str_http_method,str_url,false);
                obj_http.SetRequestHeader("Content-Type","application/x-www-form-urlencoded");
                obj_http.send(str_xml);
                var str_reply=obj_http.ResponseText;

                //processes return xml
                var xmlResponse = str_reply;
                var objXmlDOM=new ActiveXObject("Microsoft.XMLDOM");
                if(!objXmlDOM.loadXML(xmlResponse))
                {
                    alert("Could not load xml object");
                }
                else
                {
                    var i_option_id = objXmlDOM.selectNodes("/options/option_id");
                    var str_option_text = objXmlDOM.selectNodes("/options/option_text");
                    var i_loop;
                    var i_num_options=1;
                    document.frm_test.cbo_fabric_types.options.length=1;
                    for(i_loop=0;i_loop<i_option_id.length;++i_loop)
                    {
                        document.frm_test.cbo_fabric_types.options.length+=1;
                        i_num_options++;
                        document.frm_test.cbo_fabric_types.options[i_num_options-1].value=i_option_id[i_loop].text;
                        document.frm_test.cbo_fabric_types.options[i_num_options-1].text=str_option_text[i_loop].text;
                    }
                }
            }
        } 
    </script>
</head>

<body>
<form name="frm_test" method="post">
    <select name="cbo_fabric_categories" onChange="func_retrieve_fabric_types()">
        <option value="">Please select from below</option>
        <%
            Response.Write(func_fill_combo(cnn_test, "tbl_fabric_cats", "FABRIC_CAT_ID", "FABRIC_CAT_NAME",""))
        %>
    </select>
    <br><br><br>
    <select name="cbo_fabric_types">
        <option value="">Please select from below</option>
    </select>
</form>


</body>
</html>
The page (testfb.asp) which fetches related fabric types is below.

Code:
<%
    dim obj_xml_dom
    dim str_xml

    set obj_xml_dom = Server.CreateObject("Microsoft.XMLDOM")

    str_xml = Request.Form

    if (not(obj_xml_dom.loadXML(str_xml))) then
        Response.Write("No XML")
    end if

    dim obj_xml
    set obj_xml=obj_xml_dom.documentElement.childNodes.item(0)

    dim iCategoryId
    iCategoryId=obj_xml.text

    dim str_reply

    dim qry_traverse_fabric_types
    dim rst_traverse_fabric_types
    qry_traverse_fabric_types="SELECT FABRIC_ID, FABRIC_NAME FROM tbl_fabrics WHERE FABRIC_CAT_ID=" & iCategoryId
    set rst_traverse_fabric_types=Server.CreateObject("ADODB.RecordSet")
    rst_traverse_fabric_types.Open qry_traverse_fabric_types, cnn_test
    if(not(rst_traverse_fabric_types.Eof or rst_traverse_fabric_types.Bof)) then
        str_reply="<options>"
        rst_traverse_fabric_types.MoveFirst
        while(not(rst_traverse_fabric_types.Eof))
            str_reply=str_reply & "<option_id>" & rst_traverse_fabric_types("FABRIC_ID") & "</option_id>"
            str_reply=str_reply & "<option_text>" & rst_traverse_fabric_types("FABRIC_NAME") & "</option_text>"
            rst_traverse_fabric_types.MoveNext
        wend
        str_reply=str_reply & "</options>"
    else
        str_reply=""
    end if
    Response.Write(str_reply)
%>
Regarding the risk associated with this. As you can see testfb.asp page can return this value when any web page or other application (VB, C) submits the XML of the required format to it. I don't know how can we make this secure (so that it will accept only XML from a particular page). May be some other parson can suggest a method.

the function func_fill_combo is for filling a select box from database.

Hope this helps.
 
Old January 28th, 2005, 01:44 AM
Authorized User
 
Join Date: Dec 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jaywhy13 Send a message via Yahoo to jaywhy13
Default

thanks i'll b tryin the first, since i'm not too familiar with Xml

I'm gonna download the internet if its the last thing I do....
Until the algorithm is finished u must prepared to bow down and worship me (or my grave).... i figured i'll b finished b4 the latter!
 
Old January 28th, 2005, 08:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

Quote:
quote:
As most of the browsers support the iframe HTML tag, you can load a secondary document, created by a CGI, server-side includes, scripting, or other means into an embedded frame. However the document in the iframe is created, just make sure that it has a meta-refresh tag within its head tag, and it will be reloaded on a periodic basis. This will affect only the document in the iframe, and not the entire browser window. This is in fact, how many of the banner advertising system work.

--
Paul A. Howes
http://www.codeproject.com/html/topt...9236#xx29236xx

 - mega
Moving to C# .NET





Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time error '20599'; Cannot open SQL Server manishashar888 Pro VB Databases 7 March 20th, 2007 07:04 AM
Design-Time or Run-Time now ? ALGNET .NET Framework 2.0 1 July 31st, 2006 04:43 AM
Run time Help Dazzer96 Access VBA 2 May 3rd, 2006 07:03 AM
run-time error '20599' : cannot find sql server juicyfruit SQL Server 2000 1 February 16th, 2006 06:25 AM
Show server control at run time minhpx General .NET 1 March 2nd, 2005 12:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.