AJAX Problem in asp.net1.1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhappy
    New Member
    • Jul 2007
    • 139

    AJAX Problem in asp.net1.1

    Hai All,

    im facing different problem with ajax. Im using ajax code for country,state & city dropdownlists. In city dropdownlist i had an option to add new city.Im selecting other option in city dpdlist and im adding new city.the problem is it is storing in database but it is not displaying in dpdlist..?.

    (1). If i close the window and if i open again then it is displaying in dpdlist.

    (2). If i delete the cookies and temp.. files in internetexplore r then it is displaying (no need of closing the window.. )

    any programetic sollution for this...?



    Thanks,

    Aswath.
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Originally posted by bhappy
    Hai All,

    im facing different problem with ajax. Im using ajax code for country,state & city dropdownlists. In city dropdownlist i had an option to add new city.Im selecting other option in city dpdlist and im adding new city.the problem is it is storing in database but it is not displaying in dpdlist..?.

    (1). If i close the window and if i open again then it is displaying in dpdlist.

    (2). If i delete the cookies and temp.. files in internetexplore r then it is displaying (no need of closing the window.. )

    any programetic sollution for this...?



    Thanks,

    Aswath.
    After saving the city in db and getting the response from AJAX, add that new city in that city-dropdown-list.

    Check this tutorial to find how to add options.

    Comment

    • bhappy
      New Member
      • Jul 2007
      • 139

      #3
      Hai,
      Thanks for replay,

      After adding new city im filling other details in the form and im submitting all the detaills, It is saving all the details including new city.after that if i click edit button then also newcity is displaying in dpdlist.now if i want to add new record, in this case the new city is not displaying in dpdlist.(not only in this page, all pages having city dpdlists)

      Thanks,
      Aswath.

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by bhappy
        Hai,
        Thanks for replay,

        After adding new city im filling other details in the form and im submitting all the detaills, It is saving all the details including new city.after that if i click edit button then also newcity is displaying in dpdlist.now if i want to add new record, in this case the new city is not displaying in dpdlist.(not only in this page, all pages having city dpdlists)

        Thanks,
        Aswath.
        When you are about to add a new record second time, the newly added city is not there in the drop down?.. is it?
        For this I would still stand on my first reply. You may post your code to elaborate your problem.

        Comment

        • bhappy
          New Member
          • Jul 2007
          • 139

          #5
          Hai
          Thanks for replay,

          What u understood is 100% correct.i know the problem and i know the sollution in manually but i need programetically ..
          2 sollutions are there

          (A) closing the IE, then open again and it will display(newcity )
          (B) IE --> Tools --> InternetOPtions --> Delete cookies and temp. files (now without closing IE newcity is displaying)

          I need programetically ,
          my code is:
          *************** *************** *************** *************** *************** *************** ****
          [CODE=javascript]<script language="javas cript" type="text/javascript">

          var country = document.getEle mentById("drpco untry");
          var state = document.getEle mentById("drpst ate");
          var city = document.getEle mentById("drpci ty");
          var obj;

          function populatestates( )
          {
          //alert(document. getElementById( "dd_coun").valu e);
          var cid = document.getEle mentById("drpco untry").value
          obj = GetXmlHttpReque st();
          if (obj!=null )
          {
          obj.onreadystat echange = stateprocess;
          obj.open("GET", "getcategory1.a spx?id="+cid+"& status=0",true) ;
          obj.send(null);
          }
          }

          function dummycity()
          {
          var ci = document.getEle mentById("drpst ate").value
          document.getEle mentById ("txt_s1").valu e=ci
          obj = GetXmlHttpReque st();
          if (obj!=null )
          {
          obj.onreadystat echange = ncity;
          obj.open("GET", "getcategory1.a spx?id="+ci+"&s tatus=1",true);
          obj.send(null);
          }
          }


          function getplace()
          {
          var ci = document.getEle mentById("drpci ty").value
          document.getEle mentById ("txt_c1").valu e=ci
          obj = GetXmlHttpReque st();
          if (ci =="1" || ci=="Other City")

          {
          Form1.txt_other city.disabled=f alse
          Form1.txt_other city.value=""
          }
          else
          {
          Form1.txt_other city.value=""
          Form1.txt_other city.disabled=t rue
          if (obj!=null )
          {
          obj.onreadystat echange = place;
          obj.open("GET", "getcategory1.a spx?id="+ci+"&s tatus=2",true);
          obj.send(null);
          }
          }
          }
          function place()
          {
          }


          function ncity()
          {
          if(obj.readySta te == 4)
          {
          if (obj.status == 200)
          {
          retval = ""
          var retval = obj.responseTex t;
          retval += "</City>"
          clearSelect(doc ument.getElemen tById("drpcity" ));
          populatecity(re tval)
          //alert("e")
          }
          else
          {
          alert('error');
          }
          }
          }

          function stateprocess()
          {
          if(obj.readySta te == 4)
          {
          if (obj.status == 200)
          {
          retval = ""
          var retval = obj.responseTex t;
          retval += "</States>"
          clearSelect(doc ument.getElemen tById("drpstate "));
          populatestate(r etval)

          }
          else
          {
          alert('error');
          }
          }
          }

          function populatestate(r esponse)
          {
          if (window.ActiveX Object)
          {
          var xmlDoc=new ActiveXObject(" Microsoft.XMLDO M")//Create the XMLDOM object
          xmlDoc.async = false
          xmlDoc.loadXML( response)
          var opt
          var stateselem = xmlDoc.getEleme ntsByTagName("S tates")
          var stateelem = stateselem[0].getElementsByT agName("dp_stat e")
          var opt = document.create Element("option ")
          opt.setAttribut e("value",-1)
          var textnode = document.create TextNode ("Select State")
          opt.appendChild (textnode)
          document.getEle mentById ("drpstate").ap pendChild(opt)
          for (var i = 0;i<stateelem.l ength ;i++)
          {
          var textnode = document.create TextNode (stateelem[i].getAttribute(" cstate"))
          appendtoselect( document.getEle mentById ("drpstate"),st ateelem[i].getAttribute(" id"),textnode )
          }
          }
          else //Mozilla
          {
          var parser=new DOMParser();
          var doc=parser.pars eFromString(res ponse,"text/xml");
          var x=doc.documentE lement;
          //alert(x.childNo des.length)
          var opt = document.create Element("option ")
          opt.setAttribut e("value",-1)
          var textnode = document.create TextNode ("Select State")
          opt.appendChild (textnode)
          document.getEle mentById ("drpstate").ap pendChild(opt). nodeValue;
          for (var i = 0;i<x.childNode s.length ;i++)
          {
          var textnode = document.create TextNode (x.childNodes[i].getAttribute(" cstate"))
          appendtoselect( document.getEle mentById ("drpstate"),x. childNodes[i].getAttribute(" id"),textnode )
          }

          }

          }

          function populatecity(re sponse)
          {
          if (window.ActiveX Object) //----------IE
          {

          var xmlDoc=new ActiveXObject(" Microsoft.XMLDO M")//Create the XMLDOM object
          xmlDoc.async = false
          xmlDoc.loadXML( response)
          var opt
          var cityselem = xmlDoc.getEleme ntsByTagName("C ity")
          var cityelem = cityselem[0].getElementsByT agName("dp_city ")
          var opt = document.create Element("option ")
          opt.setAttribut e("value",-1)
          var textnode = document.create TextNode ("Select City")
          var textnode1 = document.create TextNode ("Other City")
          opt.appendChild (textnode)
          document.getEle mentById ("drpcity").app endChild(opt)
          appendtoselectc ity( document.getEle mentById ("drpcity"),1,t extnode1)
          for (var i = 0;i<cityelem.le ngth ;i++)
          {
          var textnode = document.create TextNode (cityelem[i].getAttribute(" ccity"))
          appendtoselectc ity( document.getEle mentById ("drpcity"),cit yelem[i].getAttribute(" id"),textnode )
          }
          }
          else // ------------- Mozilla
          {
          var parser1=new DOMParser();
          var doc=parser1.par seFromString(re sponse,"text/xml");
          var x=doc.documentE lement;
          var opt = document.create Element("option ")
          opt.setAttribut e("value",-1)
          var textnode = document.create TextNode ("Select City")
          var textnode1 = document.create TextNode ("Other City")
          opt.appendChild (textnode)
          document.getEle mentById ("drpcity").app endChild(opt).n odeValue;
          appendtoselectc ity( document.getEle mentById ("drpcity"),1,t extnode1)
          for (var i = 0;i<x.childNode s.length ;i++)
          {
          var textnode = document.create TextNode (x.childNodes[i].getAttribute(" ccity"))
          appendtoselectc ity( document.getEle mentById ("drpcity"),x.c hildNodes[i].getAttribute(" id"),textnode )
          }

          }


          }

          function GetXmlHttpReque st()
          {

          var xreq = null;
          //alert('asdf');
          if (window.XMLHttp Request)
          {
          xreq = new XMLHttpRequest( );
          }
          else if(typeof ActiveXObject != "undefined" )
          {
          xreq = new ActiveXObject(" Microsoft.XMLHT TP");
          //alert("hello"+x req);
          }
          return xreq;
          }


          function clearSelect(sel ect)
          {
          //alert(document. getElementById ("dd_state") );
          //alert(select);
          select.options. length = 0;//Set the select box's length to 1 so only "--Select--" is availale in the selection on calling this function.
          //process()
          //document.getEle mentById ("dd_city").opt ions.length = 0;//You may want to write your own clearSelect logic
          }

          function process()
          {
          if(obj.readySta te == 4)
          {

          if (obj.status == 200)
          {
          retval = ""
          var retval = obj.responseTex t;
          // alert(obj.respo nseText)
          retval += "</Country>"
          clearSelect(cou ntry);
          populatelist(re tval)
          }
          else
          {
          alert('error');
          }
          }
          }

          function appendtoselect( select,value,co ntent)
          {
          var opt
          // alert(value)
          opt = document.create Element("option ")//Create an Element of type option
          opt.setAttribut e("value",value )
          //opt.value = value;
          //Set the option's value

          opt.appendChild (content)

          //Attach the text content to the option
          document.getEle mentById ("drpstate").ap pendChild(opt)
          }

          function appendtoselectc ity(select,valu e,content)
          {
          var opt
          // alert(value)
          opt = document.create Element("option ")//Create an Element of type option
          opt.setAttribut e("value",value )
          //opt.value = value;
          //Set the option's value

          opt.appendChild (content)

          //Attach the text content to the option
          document.getEle mentById ("drpcity").app endChild(opt)
          }
          </script>
          [/CODE]

          *************** *************** *************** *************** *************** *******
          Thanks,
          Aswath.
          Last edited by acoder; Mar 1 '08, 12:07 PM. Reason: Added code tags

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            Did you test it on Firefox and Opera?


            And try adding this line in the head of your HTML[html]<meta http-equiv="cache-control" content="no-cache" />[/html]

            PS: Do include your code in the proper code tags before posting. Its easy to understand the code that way.

            Comment

            • bhappy
              New Member
              • Jul 2007
              • 139

              #7
              Hai
              Thanks for replay,

              I tried ur code <meta ........>, But it is not Happening.

              Thanks,
              Aswath.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Aswath, as a full member now, you should know that we expect your code to be posted in [CODE] tags (See How to Ask a Question).

                This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

                Please use the tags in future.

                Moderator.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by bhappy
                  What u understood is 100% correct.i know the problem and i know the sollution in manually but i need programetically ..
                  2 sollutions are there

                  (A) closing the IE, then open again and it will display(newcity )
                  (B) IE --> Tools --> InternetOPtions --> Delete cookies and temp. files (now without closing IE newcity is displaying)

                  I need programetically
                  Use an extra parameter to bust the cache, i.e. make a unique request to avoid getting the response from the cache.

                  Add this to the Ajax URL: "&t="+(new Date()).getTime (); This will force a new request.

                  Comment

                  • bhappy
                    New Member
                    • Jul 2007
                    • 139

                    #10
                    Hai

                    Many Many Thanks,
                    Your code works great.......... .........my problem solved

                    Cheers,
                    Aswath.

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      No problem, you're welcome. Glad you got it working.

                      Comment

                      Working...