Showing posts with label detect. Show all posts
Showing posts with label detect. Show all posts

Monday, March 26, 2012

Detecting UpdatePanel postback Vs regular postback

Probably a stupid question...

Is it possible to detect on the server-side whether or not the request is a full post back or an updatepanel postback?

Reason is I have a couple of controls on the page that are rather database-intensive and if since an UpdatePanel postback causes a full page cycle, if I could detect it I could avoid having those problem doing the db-intensive rendering task.

Thanks!

Ben

Hi Ben,

You can ask the scriptmanager if it's in a partial page postback, see my example in VB

If ScriptManager.GetCurrent(Me).IsInAsyncPostBack()Then'is in partial postbackEnd If


EACH CONTROL has its own events. if you bind the other controls in the page load event, enclose them with:

if not page.ispostback then

end if

the UpdatePanel has its own events where you can work on.


hi,

i don't think there is any method to identify which postback is done. According to my observation both postbacks are same


First to Check if it is AsyncPostback you can use the YourScriptManager.IsAsyncPostBack and to detect which control casued the postback use the YourScriptManager.AsyncPostBackSourceElementID.


Thanks Richard, that worked just fine (I knew that had to be simple!), marked your reply as answer.

Thanks all for your replies too.

Cheers,

Ben

Detecting point of click on Table

Hi all.
I have a Table on my page. By xml-script I can detect clicks on it.

<components>
<button id="Table1" click="DoSomething" />
</components
But I want to know coordinates of the point on this table, which was clicked. Specifically I want to have them in my function "DoSomething()"
Please, help me.

There are examples here for tracking mouse position:http://www.irt.org/script/pointer.htm

-Damien


DoSomething should be a function like so:

function DoSomethign(ev){}

ev.clientX and ev.clientY will give you the coordinates, and so on.

Detecting browser closing in session

Hi

Sorry if this is obvious but I'm new to Microsoft Ajax. Is there anything in Microsoft Ajax/Asp.net to detect when the browser is closed via the 'X' button?

thanks

No, the browser does not notify that is closes, it just quits asking data from the webserver.


No. There's no reliable way to notify the server about the browser being closed. May be some java script hack is available but it is not recommended.

detect when updatepanel has returned in javascript

Hi

I have this code which detects when an updatepanel has returned

Sys.Application.load.add( onLoad );

function

onLoad()

{

var page = $object("_PageRequestManager");

page.propertyChanged.add( changed );

}

function

changed( obj,args )

{

if (args.get_propertyName() && obj.get_inPostBack() ==false)

{

var mode = document.getElementById('<%=siteMode.ClientID %>');//so something

}

}

Is there anyway to tell if a specific update panel was activated on a particular postback and then do something when it has finished its callback.

thanks

andrea

Have you found a solution? I am also looking for the solution, and want to add one more sample here so maybe someone experienced can help (I found the code somewhere (maybe on this forum) and slightly extended it):

<%@. Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> void h(object s, EventArgs a) {txt.Text = DateTime.Now.ToString();}void h1(object s, EventArgs a) {txt1.Text = DateTime.Now.ToString();}</script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <atlas:ScriptManager runat="server" id="manager" EnablePartialRendering="true"></atlas:ScriptManager> <atlas:UpdatePanel runat="server" ID="panel"> <ContentTemplate> <asp:Literal runat="server" ID="txt" /> <asp:Button runat="server" ID="bt" OnClick="h" Text="try" /> </ContentTemplate> </atlas:UpdatePanel> <atlas:UpdatePanel runat="server" ID="pane2"> <ContentTemplate> <asp:Literal runat="server" ID="txt1" /> <asp:Button runat="server" ID="bt1" OnClick="h1" Text="try1" /> </ContentTemplate> </atlas:UpdatePanel> </form> <script type="text/javascript"> Sys.Application.load.add( onLoad );function onLoad() {var page = $object("_PageRequestManager"); page.propertyChanged.add( changed );}function changed( obj, args ) {if( args.get_propertyName() == "inPostBack" && obj.get_inPostBack() == false) {alert("refreshed" ); }}</script> </body> </html>

Extending my previous post:

so hove in javascript function "changed" we can know what update panel: panel on pane2 caused call of the javascript function?


Hi

I still havent found a solution either

andrea


Hi,

unfortunately there isn't a solution at the moment. Actually, the ID of the panel that triggered the async postback is contained in the _postbackSettings object of the PageRequestManager, but this is an object that cannot be accessed from outside.

Thus, the only possibility is to modify the source code and create a property that returns the _postbackSettings object. I hope that the team will do this in one of the next releases.

No answer, but possibly related posts have been compiled near the end of this...

http://forums.asp.net/AddPost.aspx?PostID=1373674


hi

that link takes me to a page for adding a new post

thanks


ah, so it does...perhaps this is better...

http://forums.asp.net/thread/1356742.aspx

Detect if AutoCompleteExtender is showing?

Greetings,

Looking for a way (in javascript) to detect if the autocompleteextender is currently showing?

I can get an instance of the control, I just dont know which property (if any) I should be checking?

ie

var ace = $find('myAutoCompleteExtender');
if(ace ??){ //then i'm showing do some logic

}

Any ideas?

behavior.get_showing() ?


No unfortunately that property doesn't exist on the control

The only thing I can find is "_flyoutHasFocus" however ...that's not the same as 'is the flyout showing' ...

Any other ideas?

Detect if a request is a partial postbak?

Hello,

is it possible to check if the current request is a partial postback or not?


I am getting PageRequestManagerParserErrorExceptions when i use a response filter that does a gzip compression in global.asax and my idea was to detect if the current request is a partial one. I that case i would not apply the filter.


The only question is if it is possible to detect the difference between normal and partial postbacks.

Any hints?

Ciao,

Ralf

ScriptManager.IsInAsyncPostBack.

Thanks!

My only problem is now that the process of applying the filter happens in global.asax and i have to find out how to access my scriptmanager instance (scriptmanager is contained in the masterpage) from within global.asax.


OK, i have added the scriptmanager to the application now so i cann access it from within global.asax but: When performing pagings in a gridview that is contained in an updatepanel the ScriptManager.IsAsyncPostback shows "false" (i have defined the paging events of the gridview as triggers so i expected to see IsAsyncPostback=true)

Is the IsAsyncPostBack property only valid at page level (i mean not useable in global.asax)?


I'm not sure, I'll defer to your experiences as an indicator that it's a page / instance level variable.

The request itself gets modified by the runtime, though, so that if you have an http reuqest fired by your updatepanel, it should have the additional http header of:

x-microsoftajax: Delta=true.

If you check the Request.Headers collection, that should be a way for your module to do the detection you're lookign for.

Hope that helps.

Paul


Hi Paul,

Yes, that helps! Now i can apply gzip/deflate filtersand use updatepanels without getting PageRequestManagerParserErrorExceptions by simply not using the filter on partial postbacks.

Thanks for the hint,

Ralf


Detect Browser Support for Atlas

Hi There,

I was wondering if anybody has stumbled across a way to check if the browser supports Atlas (and namely javascript). In short I am developing a component, in which I would like to implement Atlas functionality - but only if the browser supports it. If not, I would like like the page to postback as normal - I was hoping that this might be the default behaviour of Atlas, but I have disabled JS in my browser and quite simply, nothing happens...

Any suggestions would be appreciated.

Regards

Jason

hello.

well, the atlas framework does that kind of comparison on the server side when the scriptmanager component adds the necessary atlas files to the page. take a look at the onpageprerendercomplete method of the scriptmanager class to see how those scripts are added (as allways, there's no safe approach to this).


I got a question regardign this issue.

Will Atlas team consider implementing IFrame postback when activeX is disabled? I see several other frameworks that works as expected when the activeX is disabled and really makes life a lot easier here.

Thanks.

Detect AJAX postback in Application.EndRequest

Anyone know if there's a way to detect whether the current request is an AJAX postback or a regular postback from inside the Application.EndRequest event of an HttpModule? I have a module that writes out information to the end of a normal request (using response.write). However, this causes an AJAX postback request to fail. Or maybe there's a better way to append some text to the end of a request than response.write?

Ideas?

Test for (Request["X-MicrosoftAjax"] == "Delta=true"). That request header is present in partial postbacks.


Most excellent. Thanks!

HOWEVER, I'm a bit PEEVED at Microsoft for making the client-side AJAX javascript so sensitive to the data that comes back. If any part of my code does a response.write anywhere, the stupid AJAX Javascript on the client goes wobble-kneed and dies. Sheesh! I'd really like to be able to write out some text (using response.write) in both the master-page AND the httpModule's end_request event, but the AJAX Javascript on the client won't allow it! What a pain.

I've seen some c# code on the internet that shows how to modify the response that AJAX returns, but it's confusing as it's doing text translation (i.e., the function of the code is getting in the way of me understanding what it's doing to the response string).

Thanks for the answer to the original question.


Use some sort of HTTP viewer to inspect a partial postback response, and you'll probably see a way to do what you want to. Once you see it, hands-on, it's not too difficult to figure out how to alter (or see why Response.Write kills it).

I use FireBug for that, myself. I think Fiddler is a comparable IE addon.