Wednesday, March 28, 2012
Change the event that causes the popupcontrol to shows the control
Change Event not fired when changed once or more then restored to its original value.
Hi.
I am trying to ATLAS-ize an existing application with lots of Master Detail controls.
As I don't want to write a heap of new code I am using UpdatePanels rather than writing web services even though my situation is similar to the one in the CascadingDropDown example (http://atlas.asp.net/atlastoolkit/CascadingDropDown/CascadingDropDown.aspx)
The problem I have though is that if I change the master listbox selected value (say from 0 to 1) then the Update Panel refreshes fine.
If I change it back from 1 to 0 the SelectedIndexChanged event does not fire leaving a load of incompatible info in the details listbox
I'm assuming that this is because when the page was first loaded the value was 0 so it does not recognize that a change has occurred.
I'd be grateful for advice on the optimum solution to this.
Ah Problem Semi Solved!
The first thing I was doing "wrong" was that my page overrides Load and Save PageStateFromPersistenceMedium and stores it in a DB and just passes the GUID back and forth in a hidden field. This obviously means the ViewState updates never made it into my page.
I would appreciate some advice on things I can override to get this functionality back however as some of the ViewState is pretty huge but required without a lot of extra coding. Is their any way I can replicate what is happening automatically with __VIEWSTATE to my own custom hidden input (hdnViewStateId) (i.e. get it automatically submitted on a call back, get it passed back in the XML envelope and automatically update the value with the new one)
The other thing I was doing wrong was that I'd left in an old school Response.Write in my page which knackered up the XML sent! (By the way is there any way I could have switched on any error logging which would have alerted me to this last issue?)
Ah Problem Semi Solved!
The first thing I was doing "wrong" was that my page overrides Load and Save PageStateFromPersistenceMedium and stores it in a DB and just passes the GUID back and forth in a hidden field. This obviously means the ViewState updates never made it into my page.
I would appreciate some advice on things I can override to get this functionality back however as some of the ViewState is pretty huge but required without a lot of extra coding. Is their any way I can replicate what is happening automatically with __VIEWSTATE to my own custom hidden input (hdnViewStateId) (i.e. get it automatically submitted on a call back, get it passed back in the XML envelope and automatically update the value with the new one)
The other thing I was doing wrong was that I'd left in an old school Response.Write in my page which knackered up the XML sent! (By the way is there any way I could have switched on any error logging which would have alerted me to this last issue?)
Your drop down list is set to do a autopostback, correct? This would translate to a partial postback given that it's within the update panel.
Given that you've turned off the standard viewstate mechanism provided by ASP.Net, the "change" isn't going to be noticed 'cause the runtime can't compare what "was" (in the viewstate) with what "is" (in the form post). However, you can...
Take a look at this Fiddler trace of a site I quickly built using the update panel to do what you're doing with a drop down list (this is taken when the drop-down list auto posts back to the server):
POST /public/testsites/atlaswebsite3/Default.aspx HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer:http://www.ben-rush.net/public/testsites/atlaswebsite3/
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
delta: true
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Host:www.ben-rush.net
Content-Length: 305
Proxy-Connection: Keep-Alive
Pragma: no-cache
ScriptManager1=myupdatepanel&__EVENTTARGET=DropDownList1&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwUKLTgwNzIyNjA5NA9kFgICAw9kFgICAw9kFgJmD2QWAgIDDxBkZBYBZmRkrJaJXj2KU%2FOTLiUUKLu7RDDJunM%3D&DropDownList1=2&__EVENTVALIDATION=%2FwEWBALyq5BnAp3kj%2BUKApKLpYsGApOLpYsGRIPIbgqWzDqL6Q8VoLqfhZnR%2BlM%3D&
You could grep out of the form post the object that created the postbck (__EVENTTARGET), and what its postback value is (DropDownList1=2). You could store the state of the last selected item value in whatever mechanism you choose and do your own compare, even in your custom page_load.Thanks. I reckon that's probably the way to go.
I was contemplating (but probably wouldn't have actually done) a pretty horrible solution as I was playing with adding my own
__VIEWSTATE
hidden input with the GUID and it almost works if I strip out the extra "," that I get on the form post from the redundant ASP.NET added control of the same name!
I still hadn't sussed out how to change the XML envelope to reflect that change though..
When you say "change the XML envellop to reflect that change" you're talking about changing the XML response from the server that contains all the delta bits for the clientside framework, right (the XML that directs the client code to do its DHTML tricks to update the content within the UpdatePanel)?
So, before we go any further - your problem is that you can now detect when the change is made, but the atlas server code still doesn't and, therefore, doesn't include the right junk in the XML response back to the client to update the doodads in your UpdatePanel control?
Yes that's correct.
BTW: I've had a look at your blog and I suspect you're going to tell me that you know how to do this.
I'm a bit torn on the best way of doing this as.
I reckon__EVENTTARGET is probably the more robust way of doing it even though I lose a lot of the benefits of the ASP.NET module (I need to figure out how to store and retrieve the initial values of controls without using view state and raise the change events myself)
If I try and hijack the __VIEWSTATE control for my own purposes then a lot of the code is written for me already but my solution could break if a new version of ATLAS or update to ASP.NET comes out!
Actually Ben.
I've tried your suggestion and it's trickier than I thought it would be.
The problem is that when I select the original value in the Master ListBox nothing is sent back to the browser!
I assume that this is some sort of optimisation to only send back the things which are different and (as far as ASP.NET knows from looking at the old ViewState) it doesn't have to send anything back as they are the same.
It looks like I am going to need to integrate it with ViewState somehow. For the time being I've commented out my overrides and am sending all ViewState to the Client to get it working.
However I would be extremely grateful for suggestions of ways to get around this issue and get the benefits of both ServerSide ViewState Storage and ATLAS.
...let me dink around a bit with some stuff on my side here and try to duplicate what you're running into more accurately. This has got me curious about several things going on...
Can you visit this page and tell me how accurately this matches your situation:http://www.ben-rush.net/public/testsites/atlaswebsite3/.
I have a textbox and a listbox, the textbox updates its content to the selected index of the listbox when the selectedindex changes. The viewstate for the listbox is off. I don't believe that the listbox requires viewstate for identification of changes because the "change" will only occur when the index is changed; therefore a form post that includes the listbox as an eventtarget will be seen as a selectedindexchanged event. I could be wrong, but I seem to remember this being the case (I did some viewstate optimizations for a shopping cart system a long, long time ago).
Regardless, look at these two fiddler dumps, one during change from index 0 -> 1 (value 1->2), the other from 1->0 (value 2->1). Both show the value of the listbox.
POST /public/testsites/atlaswebsite3/Default.aspx HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer:http://www.ben-rush.net/public/testsites/atlaswebsite3/
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
delta: true
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Host:www.ben-rush.net
Content-Length: 288
Proxy-Connection: Keep-Alive
Pragma: no-cache
ScriptManager1=myupdatepanel&__EVENTTARGET=ListBox1&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwUJNTA5MjUzOTYxZGTFj5uiiDfrPSUZQz6IYXNKpb8xOQ%3D%3D&ListBox1=2&TextBox1=0&__EVENTVALIDATION=%2FwEWBwKJvNCXBgK9ueOMCQKy1sniBQKz1sniBQKw1sniBQKx1sniBQLs0bLrBlpXNeow%2BdPC39h7%2F1FxYfamkoLm&
And the other...
POST /public/testsites/atlaswebsite3/Default.aspx HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer:http://www.ben-rush.net/public/testsites/atlaswebsite3/
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
delta: true
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Host:www.ben-rush.net
Content-Length: 288
Proxy-Connection: Keep-Alive
Pragma: no-cache
ScriptManager1=myupdatepanel&__EVENTTARGET=ListBox1&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwUJNTA5MjUzOTYxZGTFj5uiiDfrPSUZQz6IYXNKpb8xOQ%3D%3D&ListBox1=1&TextBox1=1&__EVENTVALIDATION=%2FwEWBwKJvNCXBgK9ueOMCQKy1sniBQKz1sniBQKw1sniBQKx1sniBQLs0bLrBlpXNeow%2BdPC39h7%2F1FxYfamkoLm&
I should probably mention that I have a trigger in the UpdatePanel as well.
I suspect that it may be a trigger optimisation causing the issue (for the same reason as previously described it can't realise that there is a change to process so returns an empty envelope)
<Triggers>
<atlas:ControlEventTriggerControlID="drpMasterListBox"EventName="SelectedIndexChanged"/></Triggers>Well yes that is definitely working.
Do you have a trigger?
Is your UpdatePanel set to the same options as mine or is anything different?
(I haveMode="Conditional"RenderMode="inline")
In any event I'm thinking of doing it without update panels now and using a custom extender.
I was hoping that UpdatePanels would be a quick and dirty solution but I'm not progressing as fast as I wanted to and I suspect I may hit yet more obstacles because my UpdatePanel is in a UserControl which I was planning to embed in another UpdatePanel at Page Level.
No, I don't have a trigger. I changed my rendering modes to what you have, and it didn't change things (I wouldn't expect that it would). You can visit the same page URL I gave you earlier to confirm.
If you have a control in your update panel that does a postback automatically (say, the listbox control with its autopostback option on), then you have no need for a trigger. Triggers will only be useful for controls that don't postback automatically. I haven't researched triggers much, but if they're anything like binding objects then the control they're bound to needs to be AJAX savvy anyway.
Try turning off the trigger, I guess - and see what that does.
MartinSmithh:
The first thing I was doing "wrong" was that my page overrides Load and Save PageStateFromPersistenceMedium and stores it in a DB and just passes the GUID back and forth in a hidden field. This obviously means the ViewState updates never made it into my page.
well, though i haven't tried it, i think it's safe to assume that your field will allways be maintained if you add it to the page by using the registerhiddenfield of the clientscriptmanager api.
Change event in Ajax Update Panel
Dear All
If any event contains inside of the update panelthen after post back focus is lost. More clearly, LetTextbox1 and TextBox2 inside of the update panel.TextBox1 containsTextChanged event andthis event contains TextBox2.Focus(). But after post back it lost the focus.
Thanks
Aminul Bari
It should work just fine. Let me see if I understand what you are saying:
You've got an updatepanel.
Try to use SetFocus of ScriptManager
http://www.asp.net/AJAX/Documentation/Live/mref/O_T_System_Web_UI_ScriptManager_SetFocus.aspx
Thanks. Its working fine.
Change contents of an external update panel from within a seperate accordian panel?
Let me see if I can clarify my question further. I have a content container on a master page. Inside the content container I have a table with two cells. In the first cell I have am using the accordian control. when I click on one of the headers in the accordian control I want it to update an update panel in cell number 2. The content of the accordian panel will be just a brief headline and overview of what is displayed in the update panel in cell #2. My issue is that when trying to define triggers in the update panel in cell #2 it does not see any of the controls in cell #1. Any suggestions?
Thanks for any help you can provide.
Monday, March 26, 2012
Certain events not firing on server (but they are in dev)
I have a small web app that uses an update panel. Its asyncpostback event fires and updates a session variable. In the process, the pageload event fires and repopulates the elements within my update panel. This works in my dev environment, but doesn't work when I publish the site to my website.
The session variable is updated like it should via asyncpostback, but the pageload event isn't fired. Thus my chart within the updatepanel isn't redrawn. I have ajax installed on the server and the appropriate dll's are in the bin folder.
Any idea why this is happening?
The only thing I can think of is there are differences in your web.config file.
The web.config goes along with the publish (I've even manually copied the file over)
hello.
that is strange because the load event will always fire during a postback. have you tried hosting the app in IIS in your development environment?
Yeah I knew the web.config file went though with the Publish, but I wans't sure if you were using the Publish option in Visual Studio or if you were manually publishing it by copying the dll and aspx files. I had a few ideas as to what might be causing the problem but I keep throwing those ideas out because it is working in your test environment. At this point, I can only take guesses. I dont think AJAX.net is the problem because your session is getting updated aysnc. Since all the code is the same in both environments, that ww know of, I would next try to figure out what is different. Are the dll files different in any way, specifically the ajax dll's. Also try manually deploying the site. I have had some publshing problems with Visual Studio 2005 when publishing to ftp (The host I was using had users experieincing problems with the publish not publishing correctly.) Although the problem I and my host had was more to deal with Visual Studio stopming over some security permssions.. dont ask me how, it just did.
I have manually copied the files to the server as well (it is sitting right next to my desktop on the same domain).
hum...well, not sure on the response your chart is returning from the server. there shoudln't be any problems with it since you're seeing it work on the dev machine. anyway, how about using fiddler to see the response returned from the server ?
fiddler.. hmmm... thats a new one on me. I'll check it out.
it's an http proxy. really good to see the contents sent to and from the browser:
http://www.fiddlertool.com/
It is weird, Have you fixed it?
No, not yet. It's strange that the async call works but the page load isn't firing.
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
Catching drop event in atlas drag and drop
Thanks Shepherd. But I want to use drag and drop between two GridView's. ReorderList does not work properly for this purpose. Moreover I tried to use ReorderList with DataSource and it gives me error while reordering. Can u help me regarding this. And I want to execute a Insert command on drop event.
Thanks.
@.Kanwar,
To my knowledge this is not supported yet. I've read requests for this functionality on the AJAX Control Toolkit Codeplex site, but I don't know of any official plans to add it. I assume that it is possible, and that you could build it yourself if you have time...you might also look into some third party controls like Telerik or Infragistics. I don't know if they have controls like this, but they are usually a little ahead of the curve feature-wise. I hope this is helpful.
Best Regards...
Thanks. I am trying to build Ajax template for this.
Best of luck to you.
Catching an event from an Extender
I have written an extender and have everything working but catching an event in my .aspx page.
What is the recommended way for me to send a notification back to the application that something has happened in the extender and the page hosting the extender can take some action if it wants to?
I get the following alerts based on the code below
Client hooking into change -- at startup
add_changed -- at startup
raiseEvent: change -- when a change occurs
I have tried to use something like the following.
Control hookup in .aspx page
<psAjax:SampleExtender ID="sampleExtender" runat="server" TargetControlID="_tbName" Timeout = "250" BehaviorID="sampleExtenderBehavior"/>
Script in .aspx page
function linkBehavior()
{
var myBehavior = $find("sampleExtenderBehavior");
if (myBehavior)
{
myBehavior.add_changed(change);
}
}
function change () //This never fires
{
alert('aspx change');
}
Script in my extender .js file
add_changed : function(handler)
{
alert('add_changed');
this.get_events().addHandler('change', handler);
},
raiseEvent : function(eventName, eventArgs)
{
alert('raiseEvent: ' + eventName);
var handler = this.get_events().getHandler(eventName);
if (handler)
{
alert('Found raiseEvent: ' + eventName);
if (!eventArgs)
{
eventArgs = Sys.EventArgs.Empty;
}
handler(this, eventArgs);
}
},
I found my problem... I was not calling the linkBehavior method from pageLoad so a new behavior was created and destroyed when I called it.
I have since modified that approach and I am now registerting the event when a property is changed and this seems to work.
Is something like the following a valid way of doing things?
aspx code
<psAjax:TextChangedExtender ID="TextChangedExtender" runat="server" TargetControlID="_tbName" Timeout="250" TextChangedFunction = "onTextChanged" />
function onTextChanged()
{
alert('Client Side onTextChanged');
}
Extender .js
set_TextChangedFunction : function(value)
{
if (value != this.textChangedFunction)
{
this.remove_TextChangedHandler();
this.textChangedFunction = value;
var fn = new Function('return ' + this.textChangedFunction + '(); ');
this.add_textChanged(fn);
this.raisePropertyChanged('OnTextChanged');
}
},
Catch the active tab changed event in javascript
Hi,
I have been using the ajax tab control.
I need to catch the activetab changed event of javascript.
I want to do some processing when the users goes to a specific tab.
It would be very helpful if someone can tell me how i can do it.
Cheers
Sohail
Hi,
Well looks like i got how to catch the activetab changed event
the tab container has OnClientActiveTabChanged event.
However i still need to get some way to acces the active index in the javascript so based on it i can do some processing.
Please let me know the soltn
Cheers
Sohail Sayed
Hi Sohail,
You can use the following script to get the index of active tab:
var tc = $find("TabContainer1"); // "TabContainer1" is the client id of the TabContainer control.
var index = tc.get_activeTabIndex();
Hope this helps.
Hi,
Thx i am now able to get the active index
CascadingDropDowns cant fire OnSelectedIndexChanged client events?
Greetings, all...
I've got a page with a CascadingDropDown setup. On the third dropdown, I want to fire an update panel event to fetch data.
For whatever reason, it does not appear that I can get any of the three dropdowns in the cascade to recognize a client-side OnSelectedIndexChanged event - even when added programmatically in the code file.
The event/action are emitted correctly to the control, but it doesn't seem to fire the event.
I've been trying to find the answer in previous posts and Google, but I don't seem to be finding the answers anywhere. I'm hoping there's someone out in forumland that has seen this before and knows how to resolve the issue.
Thanks in advance for the help,
Ric Castagna
Saturday, March 24, 2012
CascadingDropDown: How to register OnChange event on client?
Hello,
I have a WebForm with three CascadingDropDown. First is the parent of second list and second is the parent of the third list. And third list has a AutoPostBack feature to populate a GridView in an UpdatePanel on the page. My challenge is clear UpdatePanel content when user change first or second lists value.
So how can I register to onChange something like event of the list on client script? Then I can use $get("UpdatePanelClientId").innerHTML="".
Regards.
Hi,
You may use the following code.
<asp:DropDownList ID="DropDownList1" runat="server" Width="170"onchange="$get('ctl00_SampleContent_UpdatePanel1').innerHTML='';"/>
You can try it on the sample website's CascadingDropDown.aspx page.
Hope this helps.
CascadingDropDown: Fire an Event
I have created a custom control that contains 3 CascadingDropDown boxes.
I would like to have the control fire a custom event when each of the "TextChanged" or "SelectedIndexChanged" events from the Drop Down items change.
I have added the appropriate "events" into my code behind, but they do not seem to fire. Does the JavaScript intercept them?
Any help would be greatly appreciated.
Thanks,
Bryan
Mr. Anson,
Perhaps you could point me in a better direction for my needs.
The Custom Control that I have created consists of 3 CascadingDropDowns that allow the user to select a Location, Skill, and Supervisor (basically this is like the Make/Model/Color sample for the car.).
My control works fine when I incorporate a button to run a report on a different page. My Button_OnClick event can see what values are in my control, and it will send them to the new page.
I would like to incorporate my current control on a page to help narrow down yet another Drop Down List.
In the CDD example, after the user selects the Make/Model/Color, I would like to pull a list of Vehicles by Year to select.
How would I go about hooking up a new CDD that requires the control to have filled in the Make/Model/Color before it can go out and find it's data?
I thought that I could do something like placing the control and drop down list inside an update panel, but I am a little fuzzy on how to continue from there.
Would I need to set up an Atlas Trigger?
Any help that you can provide would be greatly appreciated. It would even help if you could point me in a better direction.
Thanks, Bryan
Could you add a ByYear CDD that has the Color CDD as its parent? That way it automatically populates when the Make/Model/Color are filled in. And it's welcome to call a completely different web service, so it can get whatever data it wants.
If my Make/Model/Color are in a seperate control, how will I be able to give my Year CDD the parent that is inside the control? Can I just expose the CDD as a public member?
I don't want to add the Year CDD into my control. A different page may want to populate a different CDD from the data that the control provides.
You could manually hook some script up to the "onchanged" event on the client-side select element, but it's probably ultimately the same problem as above with respect to how the Year can see into the control to get the right elements.
CascadingDropDown SelectedIndexChanged FormView
Hi all,
I just found out that if I put a cascadingDropDownList with some dropDownLists, that have the OnSelectedIndexChanged event, inside a FormView, that event doesn't fire at the first time for the first dropdownlist.
This code works fine:
Ilha:But if I put it inside an InsertItemTemplate of a FormView, when I change the selected index of the first DDL at the first time, it doesn't go to theddlIlhas_SelectedIndexChanged handler. Anyone has any idea of what is going on here?Hi i am having exactly the same problem. I've been investigating this problem and it only seems to happen when used within the FormView. I'm quite new to the ajax control toolkit but if i find a solution i will let you know. Hope this helps.
<asp:DropDownList ID="ddlIlhas" runat="server" OnSelectedIndexChanged="ddlIlhas_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
<br /
Concelho:
<asp:DropDownList ID="ddlConcelhos" runat="server" OnSelectedIndexChanged="ddlConcelhos_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
<br /
<atlasToolkit:CascadingDropDown ID="ddlPanel" runat="server">
<atlasToolkit:CascadingDropDownProperties ID="propIlha" Category="Ilha" LoadingText="[A carregar...]" PromptText="Escolher..." ServiceMethod="GetIlhas" TargetControlID="ddlIlhas" ServicePath="/EDA.SGI.Website/WebService.asmx" />
<atlasToolkit:CascadingDropDownProperties ID="propConcelho" Category="Concelho" LoadingText="[A carregar...]" ParentControlID="ddlIlhas" PromptText="Escolher..." ServiceMethod="GetConcelhosByIlha" ServicePath="/EDA.SGI.Website/WebService.asmx" TargetControlID="ddlConcelhos" />
</atlasToolkit:CascadingDropDown>
</InsertItemTemplate>
The syntax above (CascadingDropDownProperties) indicates that you're using a quite old build of both ASP.NET AJAX and the AJAX Control Toolkit. Please try upgrading to ASP.NET AJAX 1.0 and Toolkit 10301, both of which are available fromhttp://asp.net/ as we've made numerous improvements since the old builds you seem to be using. Thank you!
Hi i am using the latest build and the problem still exists. I have uploaded the sample website with a few additions to show you:
http://www.flixon.com/AjaxControlToolkit.rar
Within the CascadingDropDown folder in the sample website there's now two new files:
Test.aspx - Without FormView (SelectedIndexChanged works fine)
Test2.aspx - With FormView (SelectedIndexChanged doesn't fire on first change)
Appreciate if you could help. Thanks
Sorry, I haven't managed to track this down all the way and I've run out of time just now. It definitely seems to be related to CascadingDropDown somehow since adding a plain DropDownList doesn't show the problem. I've tried commenting out the two event handlers in CascadingDropDownBehavior, but that didn't seem to do the trick. A quick web search turned up the following two articles which seem like they may provide a clue:
http://www.mikepope.com/blog/displayblog.aspx?permalink=1629
http://www.manuelabadia.com/blog/PermaLink,guid,a2abee08-bb7f-4fe5-8a24-6e56da99172a.aspx
If nothing else, pleaseopen a work item to track this bug. Thank you!
Hi, i added a work item a few weeks back:
http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=9454
Nothing has been posted yet. I will take a look at the posts you provided hopefully later today. Thanks for your help.
Hi, i've had a look but this goes straight over my head. If someone does find a solution then that would be great.
FYI, I just updatedwork item 9454 with the following notes:
Ted and I looked into this some just now. What appears to ultimately be the problem is that CascadingDropDown (and, in fact, ExtenderBase from which it derives) isn't seeing its CascadingDropDown_ClientStateValuesLoaded/Page_PreLoad method getting called when placed in a FormView's template. That ends up causing some different behavior due to the contents of the DropDownList being empty at first. The following page goes into some more detail about how the page lifecycle is different within a template and so this is probably a more general issue we should review for the Toolkit as a whole:http://msdn2.microsoft.com/en-us/library/ms178472.aspx.
What's good is that adding the following as the contents of the DropDownList seems to work around the problem for now (it's an empty ListItem that'll get replaced by CascadingDropDown once it populates the list): "<asp:ListItem></asp:ListItem>". With that, the sample code in Test2.aspx in the RAR fromhttp://forums.asp.net/thread/1671609.aspx works as expected.
Hi David
Thanks for your attention with this problem thus far. I am having a similar problem to this, but wherever I search, I get redirected back to this posting, so I'm adding my comments here. I am trying to use a set of 4 CascadingDropDowns to select a car model (sound familiar? ) . When the user selects the final drop-down, I want to create a set of check boxes based on the last drop-down's value. I am not using a FormView, just a simple form. The SelectedIndexChanged event is not firing straight away. I have another field in the form (vehicle registration date), on which the check box set also depends, so I have an OnTextChanged event set for this too. With me so far? Now, if I fill the drop-downs in a cascade using a modal window (all of which seems to work nicely), the SelectedIndexChanged event is not firing on the last drop-down. If, however, after this, I then change my text box value, the SelectedIndexChanged event for the drop-down chooses this moment to fire, followed by the OnTextChanged event for the text box. It's as if the event is getting held up or saved for later use. Is this all part of the same problem? Is there a work around I can use?
Here's my page code:
<span class="oneline" id="spDVLALookup" runat="server" visible="false"> <asp:Button ID="btnDVLALookup" Text="DVLA Lookup" runat="server" Visible="false" /></span><span class="oneline"> <span class="txtName">Manufacturer: </span><asp:DropDownList ID="ddManuf" runat="server" Width="300"> </asp:DropDownList></span><br /><span class="oneline"> <span class="txtName">Range: </span><asp:DropDownList ID="ddRange" runat="server" Width="300"></asp:DropDownList></span><br /><span class="oneline"> <span class="txtName">Model: </span><asp:DropDownList ID="ddModel" runat="server" Width="300"></asp:DropDownList></span><br /><span class="oneline"> <span class="txtName">Derivative: </span> <asp:DropDownList ID="ddDeriv" AutoPostBack="true" OnSelectedIndexChanged="ddDeriv_SelectedIndexChanged" runat="server" Width="300"> <asp:ListItem></asp:ListItem> </asp:DropDownList></span><br /><span class="oneline"> <span class="txtName">Date First Registered: </span> <asp:TextBox ID="tb1stRegDate" runat="server" Width="300" AutoPostBack="true" OnTextChanged="tb1stRegDate_TextChanged" /></span><br /><cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="ddManuf" Category="Manuf" PromptText="-- Manufacturer --" LoadingText="[Loading manufacturers...]" ServicePath="~/Services/CAPData.asmx" ServiceMethod="GetData" /><cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="ddRange" Category="Range" PromptText="-- Range --" LoadingText="[Loading ranges...]" ServicePath="~/Services/CAPData.asmx" ServiceMethod="GetData" ParentControlID="ddManuf" /><cc1:CascadingDropDown ID="CascadingDropDown3" runat="server" TargetControlID="ddModel" Category="Model" PromptText="-- Model --" LoadingText="[Loading models...]" ServicePath="~/Services/CAPData.asmx" ServiceMethod="GetData" ParentControlID="ddRange" /><cc1:CascadingDropDown ID="CascadingDropDown4" runat="server" TargetControlID="ddDeriv" Category="Deriv" PromptText="-- Derivative --" LoadingText="[Loading derivatives...]" ServicePath="~/Services/CAPData.asmx" ServiceMethod="GetData" ParentControlID="ddModel" />
Here's the code to enable the button at the top:
// Add the DVLA lookup buttonif (myVt.VIN.Length > 0 || myVt.Registration.Length > 0){ spDVLALookup.Visible =true; btnDVLALookup.Visible =true; btnDVLALookup.OnClientClick ="this.value='Please Wait'; this.disabled=true; DVLALookup(this, '" + myVt.VIN +"', '" + myVt.Registration +"');";}
Here's the JavaScript which does the modal window lookup (this JavaScript is not in the page Head because this page sits in a Master page):
function DVLALookup(button, vin, reg){ aryValues = new Array(); button.disabled = true; button.value = "Please Wait"; var url = "../../ExperianCapData/GetExperianData.aspx?vin=" + vin + "?istration=" + reg; if (navigator.appName != "Netscape") { lleft = (screen.availWidth/2) + 80; ttop = (screen.availHeight/2)-250; } strTemp = window.showModalDialog(url,aryValues,"dialogWidth:400px;dialogHeight:500px;dialogLeft:"+lleft+"px;dialogTop:"+ttop+"px;center:no;resizable:no;status:no;"); button.disabled = false; button.value = "DVLA Lookup"; if (strTemp.length > 0 && document.forms[0].ctl00_main_hfCapCode != null) { document.forms[0].ctl00_main_hfCapCode.value = strTemp; }}
Actually, I've fixed this by putting the value from the modal window (as you might have guessed from the last line of my JavaScript) into a hidden field which fires a OnValueChanged event, which in turn populates the drop-downs with the correctly selected items. I then have a logic check in my SelectedValueChanged method for the final drop-down ("derivative"), which only creates my set of check boxes for the SelectedValueChanged event if the value of the bottom drop-down is different from the one in the hidden field. This allows users to select a derivative manually (i.e. not via the modal window lookup). Also, if the SelectedValueChanged event gets delayed and fired at the same time (well OK just before) the ValueChanged event for my registration date field, it will see that its value is the same as the hidden one, so it won't try to set off the creation of the check boxes.
It's a bit clumsy, but it works. Of course, in the future I might try to split this form into TabPanels or AccordionPanes - although there was a problem with the latter, which I've forgotten. Meanwhile, if anyone can see an obvious flaw in my logic or a better way to do this, or even solve why the drop-down SelectedValueChanged event is getting delayed by one postback, please feel free to comment
Cheers, Mundo
Wednesday, March 21, 2012
CascadingDropDown require EventVlidation=false?
I turned on event validation (=true) of the Atlas Control Toolkit sample -> CascadingDropDown .
When I click the , Error message suggest turn event validation off.
Is this a must?
I saw some thread showing that they can add an attribute "SuppressEventValidation", but I can't see smart tag/ code hints in my version? Is it a new feature in later built of atlas?
Please advice how to keep EventValidated ?
This thread explains why I believe EnableEventValidation needs to be false:http://forums.asp.net/thread/1281139.aspxThanks for your kindly reference, It's really a time for me to choose between SECURITY , USABLITILY
I need to sacrifice security , choose usablitiliy
CascadingDropDown OnSelectedIndexChanged event not firing
Help!!!
I have 4 drop down list boxes that are extended by the CascadingDropDown control. All of the controls populate in sequence. I am using the OnSelectedIndexChanged event of the 4th DDL to trigger an UpdatePanel. I want to take the selection from the DDL (cmbPart) and add the item to the ListBox (lbParts). When I change the selection in cmbPart, no event fires. When I press the button on the panel (btnRemovefromList) the cmbPart_SelectedIndexChanged event DOES fire before the btnRemovefromList_Click event. I have also tried to use OnSelectedIndexChanged to fire a client side javascript function and that does not fire either. However, the onblur and onclick events DO fire.
According to previous posts on this topic, it was fixed. I have the 1.0.60914.0 version of the AtlasControlToolkit.dll installed along with version 2.0.50727.60725 of Microsoft.Web.Atlas.dll.
Ken J.
Here is the code:
<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"EnableEventValidation="false"%>
<%@dotnet.itags.org.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="atlasToolkit" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"/>
<div>
Year<asp:dropdownlistid="cmbFrom"tabIndex="2"runat="server"Width="120px">
</asp:dropdownlist>
<atlasToolkit:CascadingDropDownID="CascadingDropDown1"runat="server">
<atlasToolkit:CascadingDropDownProperties
TargetControlID="cmbFrom"
Category="Year"
LoadingText="{Loading Years...}"
PromptText="Select a Year"
ServicePath="EOLDataService.asmx"
ServiceMethod="GetYears"
/>
<atlasToolkit:CascadingDropDownProperties
TargetControlID="cmbMake"
ParentControlID="cmbFrom"
Category="Make"
LoadingText="{Loading Makes...}"
PromptText="Select a Make"
ServicePath="EOLDataService.asmx"
ServiceMethod="GetMakes"/>
<atlasToolkit:CascadingDropDownProperties
TargetControlID="cmbModel"
ParentControlID="cmbMake"
Category="Model"
LoadingText="{Loading Models...}"
PromptText="Select a Model"
ServicePath="EOLDataService.asmx"
ServiceMethod="GetModels"/>
<atlasToolkit:CascadingDropDownProperties
TargetControlID="cmbPart"
ParentControlID="cmbModel"
Category="Part"
LoadingText="{Loading Parts...}"
PromptText="Select Parts"
ServicePath="EOLDataService.asmx"
ServiceMethod="GetParts"/>
</atlasToolkit:CascadingDropDown>
Make<asp:dropdownlistid="cmbMake"tabIndex="3"runat="server"Width="215px"></asp:dropdownlist>
Model<asp:dropdownlistid="cmbModel"tabIndex="4"runat="server"Width="250px"></asp:dropdownlist>
<INPUTid="txtPartType"type="hidden"runat="server"NAME="txtPartType">
<asp:labelid="lparterr"runat="server"Width="216px"ForeColor="Red"></asp:label>
<atlas:UpdatePanelID="upParts"runat="server"Mode="conditional">
<ContentTemplate>
Part<asp:DropDownListID="cmbPart"runat="server"Width="250px"OnSelectedIndexChanged="cmbPart_SelectedIndexChanged"></asp:DropDownList>
Selected Parts<asp:ListBoxid="lbSelected"tabIndex="10"runat="server"Width="215px"Height="85px"SelectionMode="Multiple"></asp:ListBox>
<asp:Buttonid="btnRemovefromList"style="WIDTH: 54px; font-size:xx-small"tabIndex="9"Text="Remove"
runat="server"onclick="btnRemovefromList_Click"/>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTriggerControlID="cmbPart"EventName="SelectedIndexChanged"/>
<atlas:ControlEventTriggerControlID="btnRemoveFromList"EventName="Click"/>
</Triggers>
</atlas:UpdatePanel>
</div>
</form>
<scripttype="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<references>
</references>
<components>
</components>
</page>
</script>
</body>
</html>
And the code behind:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
publicpartialclass_Default : System.Web.UI.Page
{
protectedvoid Page_Load(object sender,EventArgs e)
{
}
protectedvoid cmbPart_SelectedIndexChanged(object sender,EventArgs e)
{
lparterr.Text ="test";
}
protectedvoid btnRemovefromList_Click(object sender,EventArgs e)
{
lparterr.Text ="Test";
}
}
Maybe have a look atthis post?Thanks David.
I found that the final DDL had to have AutoPostBack set to true. I also found that using the UpdatePanel to contain only the control I want updated by the ControlEventTrigger. If the DDL controls are contained in the UpdatePanel you will see the CascadingDropDown extender refresh each of the DDLs.
Ken J.