Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

dopostbak event

Hi All,

Is it possible to catch asp.net's do postback event in javascript?

I have the following code that opens and collapses a <div>;-

<script language="JavaScript" type="text/javascript">
  var openedObj = false;
  function toggleDisplay(id)
    {
    obj = document.getElementById(id);
    if (obj.style.display == "none")
    {
           if(openedObj) openedObj.style.display = "none";
           obj.style.display = "";
           openedObj = obj;
    }
    else
    {
          obj.style.display = "none";
    }
  }
</script>

But when a user is sorting or paging the Gridview within the <div>, I don't want the <div> ton collapse so I need to ensure that the above code is not executing if its a dopostback event, is this possible?
0
claracruz
Asked:
claracruz
  • 2
  • 2
1 Solution
 
jonorossiCommented:
The ASP.NET IsPostBack property tells you if there was a postback. A postback is defined as a request back to the server that uses the POST HTTP method. Client side JavaScript runs on the user's web browser and cannot interact with events that occur on the server. You however could look at using AJAX for sorting and paging of your gridview; one product you might have heard of is Microsoft Atlas which is very easy to achieve what you want with an UpdatePanel.

Hope that helps, Jono
0
 
claracruzAuthor Commented:
Atlas is not an option at th moment, I can't get my head around it and am pressed for time on this.

Is there a simple way of going about this in c#

in asp, I was able to use the GetXmlHttpObject, is this possible in asp.net, like so


      function setAccessoryOptions(locker_option_id)
      {
      var url="setaccessoryopt.asp?sid=" + Math.random() + "&o=" + locker_option_id
      //alert(url)
      xmlHttp=GetXmlHttpObject(stateChanged)
      xmlHttp.open("GET", url , false)
      xmlHttp.send(null)
      }

function stateChanged()
{
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
              ///do stuff
         }

}

will it follow the same priciple,
0
 
jonorossiCommented:
Atlas is one of the most simplest AJAX frameworks out there, it takes 2 seconds to throw an UpdatePanel around your current controls and it just works, you don't have to make web services and the likes (thats the other option with Atlas). You might want to take a look at one of the videos about Atlas at atlas.asp.net or on channel9.msdn.com

However, you can use the HttpXmlRequest object just like in ASP; this object runs on the clients web browser. The HttpXmlRequest is the core to AJAX and is what all AJAX frameworks use including Atlas.

Hope that helps
0
 
claracruzAuthor Commented:
ok, will give it a shot!!! cheers!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now