Showing posts with label state. Show all posts
Showing posts with label state. Show all posts

Monday, March 26, 2012

Catching form Submit and PageRequestManager Submit

We want to save some state on an Extender just before the page is posted back or submitted. We were just listening to the form's submit event

$addHandler(form,"submit", this._formSubmitDelegate);

but that doesn't fire when we postback is via a LinkButton so I want to catch that happening and reuse the same delegate.

I looked at using

 $addHandler(Sys.WebForms.PageRequestManager.getInstance(),'endrequest',this._endRequestDelegate);

but add Handler did not like non DOM elements being passed in. I then tried

 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(this.endRequestHandler);
But the value of "this" was not what I was expecting. I am currently trying
if (typeof(Sys.WebForms)!=="undefined" &&typeof(Sys.WebForms.PageRequestManager)!=="undefined"){ Array.add(Sys.WebForms.PageRequestManager.getInstance()._onSubmitStatements,this._formSubmitDelegate); }else { $addHandler(form,"submit",this._formSubmitDelegate); }

This seems to call formSubmitDelegate and all works well. I realise i am accessing _onSubmitStatements which should be considered private. Am I cheating? What is the correct way of doing it?

TIA

Paddeo

Hi Paddeo,

Why the second one doesn't meet your requirement?

It's the recommended way that how a handler is added.


Well when my page is "Posted back" and that postback is caused by something causing validation WebForm_DoPostbackWithOptions is called. At the end of that routine it passes off to a ASP.NET AJAX routine that will do the "postback" using a WebRequest. That does NOT cause our Form Submit event to fire.

I thought I could get around this by trapping both the Submit AND adding to the _onSubmitStatements array (I realise that my eariler post was doing it OR the other) however this is still not enough. If I had a simple AutoPost=True ASP.Net CheckBox that calls _doPostback that exists in the page itself. This does not cause my onSubmitStatements to fire nor does it call DoPostbackWithOptions so yet again I have an issue with reliably catching postbacks and submits.

To this end I am going to give up trying to lazy write to state and just serilaise it every time it changes.

Pat


Saving client state on PropertyChanged event.


Yes, sorry I should have reported back. PropertyChanged is exactly what i changed to and that works much better. Even the approaches above were not enough to catch all the postbacks

Saturday, March 24, 2012

CascadingDropDown Work only locally

HI,

I basically followed the sample toolkitCascadingdropdown. i only need 2 dropdown lists - Country and State.

everything works find on both local and live server. but when I'm calling the webservice from another website it has problems - a javascript error

<asp:DropDownList ID="ddlCountry" runat="server" />
<asp:DropDownList ID="ddlState" runat="server" />

<ajaxtoolkit:cascadingdropdown id="CascadingDropDown1" runat="server" category="State" loadingtext="Please wait..." parentcontrolid="ddlCountry" prompttext="Select a country"
servicemethod="GetStatByCountryID" servicepath="http://www.domainname.com/WebService/AddressService.asmx" targetcontrolid="ddlState">
</ajaxtoolkit:cascadingdropdown>

all sample I've seen is for working locally - both dropdownlists and webservice are sitting in the same website.

wondering if anyone can show me show to implement this cascadingdropdown by calling an external webservice

much appreciated

Hi,

So your intention is to call a external web service?

XmlHttpRequest object can't access external web service directly for security reasons. So, you may achieve this by adding a web service in the same domain, and this web service calls the external service. On client side, use this new web service to access the external web service indirectly.

Hope this helps.


This is exactly what I did, works out perfectly.

I created a local webserivce calling the external one.

much appreciated for your reply.

Wednesday, March 21, 2012

CascadingDropDown incompatible with WebServices using GET?

I'm using a trio of cascadingdropdowns representing country/state/city throughout a web application I'm developing for a client. They've recently reduced their internet speed dramatically (from 7mbps to 728k) and suddenly I've had to become more concerned about bandwidth usage.

I'd like to switch my webservice to use GET so that client browsers can cache the results without re-requesting from the server, unfortunately when I try, my select boxes show the error: 12030 (occasionally 12031)

WebService Code:

1<Services.WebMethod(cacheduration:=60), Script.Services.ScriptMethod()> _2Public Function GetCountries(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As CascadingDropDownNameValue()3Dim cachedurationAs TimeSpan = TimeSpan.FromMinutes(1)4Dim maxageAs System.Reflection.FieldInfo = HttpContext.Current.Response.Cache.GetType().GetField("_maxAge", Reflection.BindingFlags.InstanceOr Reflection.BindingFlags.NonPublic)5 maxage.SetValue(HttpContext.Current.Response.Cache, cacheduration)6 Context.Response.Cache.SetCacheability(HttpCacheability.Public)7 Context.Response.Cache.SetExpires(Now.Add(cacheduration))8 Context.Response.Cache.AppendCacheExtension("must-revalidate, proxy-revalidate")9Dim cadapterAs New ltcodebehind.DSTablesTableAdapters.countryTableAdapter10Dim ctableAs New ltcodebehind.DSTables.countryDataTable11 cadapter.Fill(ctable)12Dim valuesAs New List(Of CascadingDropDownNameValue)13For iAs Integer = 0To ctable.Count - 114 values.Add(New CascadingDropDownNameValue(ctable(i).Title, ctable(i).ID))15Next1617 Return values.ToArray1819End Function

Client source code

1 <asp:ScriptManager runat="server" ID="acm1" >23 </asp:ScriptManager>4 <ajaxtoolkit:CascadingDropDown runat="server" ID="atlascascmgr" ServicePath="../Services/skService.asmx" SelectedValue="229" Category="country" ServiceMethod="GetCountries" TargetControlID="ddlcountry" />5 Country<br />6 <asp:DropDownList ID="ddlcountry" runat="server" />

Some notes

The only different on whether I receive an error 12030 is whether I have theusehttpget:=Truein the scriptmethod, so my cascadingdropdowns are configured properly for POST operations, I specifically need to know what I can change to get it to accept GET operations.

Usually its around this time that someone might offer up serverside caching, so I'm going to go ahead and answer that question now. 1) I appreciate the goodwill, I'm not being snarky, just trying to preemptively headd of the answer 2) I'm caching the webservice via the cacheduration:=60 up above, it just doesn't help because the server has power to spare, its the clients browsers that need the help.

Thanks everyone for their potential answers. :)

The third parameter to ASP.NET AJAX's Sys.Net.WebServiceProxy.invoke method is called "useGet" and tells it whether to use GET or POST for the web service call. The Toolkit's CascadingDropDownBehavior.js currently hard-codes this parameter to false (meaning "use POST"), so that's likely the source of the problem here. You should be able to change the value to true and rebuild for your client. If that works for you, pleaseopen a work item to ask that we expose this setting as a parameter to CascadingDropDown extender itself so that it will be easy to change for others who might want to do so. Thank you!

Very interesting, I'll do it when I have the time and if it works, open the work item like you describe.

Thanks!