Showing posts with label inside. Show all posts
Showing posts with label inside. Show all posts

Wednesday, March 28, 2012

change the mode of a DETAILSVIEW to INSERT mode as soon as a NEW RECORD is inserted in the

Hi, In ASP.NET 2.0 with AJAX, i have a fairly long-size form. I have lots of DETAILSVIEW on screem inside UPDATEPANELS from AJAX. The postbacks occur corrrectly without updating the entire page.

Now, i want to automatically change the mode of a DETAILSVIEW to INSERT mode as soon as a NEW RECORD is inserted in the DETAILSVIEW.

How can i accomplish this ?

Alex

assuming that detailsview will return to readonly mode, you can set following in load_complete (not load)

If DetailsView1.CurrentMode = DetailsViewMode.ReadOnly Then DetailsView1.ChangeMode(DetailsViewMode.Insert)End If

hope this helps.

Jae.

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.

Monday, March 26, 2012

Chanage button visibility if the button is outside of the UpdatePanel

Hello everyone,

Here is my scenario, and my problem.

I have a grid inside an UpdatePanel_1. The grid is populated after a Search button inside another UpdatePanel_0 is clicked (this is actually an user control and UpdatePanel_0 is inside the user control). This works fine.

I want to provide an Export button which exports the data from the grid to Excel, but want to show it only if the grid has any records.

If I add the button to UpdatePanel_1 the visibility toggling works fine, but when I click on the button I get the nasty message:

"Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), Response filters, HTTP modules, or trace is enabled... "

And of course, I am using Response.Write for the Export of the grid to Excel.

If I put the Export button out of UpdatePanel_1, the Export works fine, but I cannot find a way to toggle the visiblity of the button. I set the visibility in the code behind when the grid has some records, but it doesn't seem to work (probably because the button is outside of the UpdatePanel_1).

What should I do to make the Exprot work and the button to appear only when I want it?

Thank you!

You could add the button to the UpdatePanelGridView and add an async trigger for the gridview databind event. So on databind, if gridview is empty your button will not show.


Hi Denis,

Thank you for your reply.

Setting the visibility of the button is not a problem when the button is inside the UpdatePanel. The problem in this case is that Export to Excel, which has to happen when the user pushes the button, doesn't work because of the error mentioned above (and the reason for the error is the Response.Write statement in the function below).

If I put the button out of the UpdatePanel, the Export to Excel works, but I have no control over the button's visibility, because it depends on the GridView records, which is inside an UpdatePanel.

Here is the function I use for the Export:

Public Sub ExportGridToExcel(ByVal grvBusinessAs GridView,ByVal pageAs Page,ByVal fileNameAs String)If grvBusiness.Rows.Count.ToString + 1 < 65536Then Dim twAs New StringWriter()Dim hwAs New System.Web.UI.HtmlTextWriter(tw)Dim frmAs HtmlForm =New HtmlForm() page.Response.ContentType ="application/vnd.ms-excel" page.Response.AddHeader("content-disposition","attachment;filename=" & fileName &".xls") page.Response.Charset ="" page.EnableViewState =False page.Controls.Add(frm) frm.Controls.Add(grvBusiness) frm.RenderControl(hw) page.Response.Write(tw.ToString()) page.Response.End()End If End Sub
I am still new to AJAX so little things like this are not easy to solve.Wink

Centering AlwaysVisibleControl?

I'm using an update progress control inside of an always visible control to communicate to users when my application is loading data. I want to center the control on the screen but have seen no way by which to do this. Has anyone figured out a way to position the AVC in the center of the browser screen? Is there a better way to do this?

In the html for your panel you define an outer div with width and height set to 100%, a transparent background and text centered. An inner div is set with a solid background and the top attrib set to 50% or some offset. The inner div will then be centered within the outer div.

catching the postBacks of UserControl inside another UserControl

My problem is that i've got:

MasterPage with a Menu, ScriptManager and a UpdatePanel, inside of wich i've put the the ContentPlaceHolder. I've put the Menu as trigger for the UpdatePanel

In the ContentPage i want to show, i have a UserControl that has inside of itself another UserControl.

Even putting an UpdatePanel in the ContentPage containing the UserControl (Parent), the whole page refreshes instead of been only the ContentPage, due to the UpdatePanel of the MasterPage.

All the UpdatePanels have de UpdateMode as Conditional.

How can i make this work, refreshing only the contentPage or the area pretended of the contentPage?

i've seen other Posts, but they only talk of one UserControl.

Thanks a lot.

You've got two problems:

First, the menu control is not compatible with partial-page updates and therefore not compatible with updatepanel controls.

Second, if you are using a master page, you are going to get a full refreshevery time you load a content page. When you navigate to a content page, you are not just reloading the part of the page that is in the contentplaceholder. You are loading anentire page that is a meshing of the master and content page. So what you are trying to do is not possible. Placing an updatepanel around a contentplaceholder does nothing. Different page = refresh.


thanks for your answer, but what i meant was the case of the usercontrols. the use of them makes me refresh the whole page, even though the content page is inside a update panel, i've tried to put the control inside a updatepanel conditional mode, but it still doesn't work.

this usercontrol was another one inside itself.


See if this article helps:

http://asp.net/ajax/documentation/live/tutorials/UsingUpdatePanelUserControls.aspx

Saturday, March 24, 2012

CascadingDropDownlist: How Do I Save the SelectedValue Back To Database

I'm using the AJAX CascadingDropDown extender inside a FormView's InsertItemTemplate.
Question: What is the correct way to save the CascadingDropDown 's selected value back to the database?

I've tried do it by setting the SelectedValue in the CascadingDropDown tag (not the DropDownList) like this:
SelectedValue='<%# Bind("SellerRegionId") %>'

However, when trying to save, this fails with error "Input string was not in a correct format."

I've been able to make it work by setting the Values dictionary in the FormView's ItemInserting() event handler, using the SelectedValue of the DropDownList control (not the extender), as follows:
e.Values["SellerRegionId"] = sellerRegionDropDownList.SelectedValue;

Is this the correct way to do this?

Thanks, in advance, for any help you can give.

Yes the latter should work and in my own opinion personally is more efficient.

CascadingDropDown SelectedValue Attribute in GridView giving Error

I have a CascadingDropDown inside of an GridView EditItemTemplate. Code is below. I need the SelectedValue of the CascadingDropDown to come from the database when then user Edit's the row. I tried addingSelectedValue='<%# Bind("sentity") %>' but I get this error:

Parser Error Message:The CascadingDropDownProperties control with a two-way databinding to field sentity must have an ID.

Source Error:

Line 67: Line 68: <atlasToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server">Line 69: <atlasToolkit:CascadingDropDownPropertiesLine 70: TargetControlID="ddlEditEntity" Line 71: Category="Entity"

<asp:TemplateFieldHeaderText="Entity">

<EditItemTemplate><asp:DropDownListID="ddlEditEntity"runat="server"CssClass="dropDownList"/><atlasToolkit:CascadingDropDownID="CascadingDropDown2"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditEntity"Category="Entity"PromptText="<-- Selected an Entity -->"ServicePath="webservices/ws_Timetracking.asmx"ServiceMethod="GetEntitesText"SelectedValue='<%# Bind("sentity") %>'/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditProperty"ParentControlID="ddlEditEntity"PromptText="<-- Select a Property -->"ServiceMethod="GetPropsForEntitytext"ServicePath="webservices/ws_Timetracking.asmx"Category="Property"/></atlasToolkit:CascadingDropDown></EditItemTemplate><ItemStyleHorizontalAlign="Left"Width="20%"/><HeaderStyleHorizontalAlign="Left"/><ItemTemplate><asp:LabelID="lblEntity"runat="server"Text='<%# Bind("sentity") %>'></asp:Label></ItemTemplate></asp:TemplateField>As you've noted, the Toolkit controls don't support data binding yet. (Though we have plans to do so soon!) For the time being, I believe you can override your page's OnDataBind method and set the SelectedValue in code. I think Shawn's posted an example of this to the forum. If that's not enough to get you going, reply back and I'll post a sample.

David, I tried setting the selectedValue for the dropdownlist in theGridView1_RowUpdating method, but it seems to not be working.

GridViewRow row = GridView1.Rows[e.RowIndex];
DataKey datakey = GridView1.DataKeys[e.RowIndex];
// Get hmy for updating the database
int hmy =Convert.ToInt32(datakey.Value.ToString());

if (row !=null)
{
DropDownList ddlEditEntity = row.FindControl("ddlEditEntity")asDropDownList;
DropDownList ddlEditProperty = row.FindControl("ddlEditProperty")asDropDownList;
TextBox txtEditDescription = row.FindControl("txtEditDescription")asTextBox;
TextBox txtEditHours = row.FindControl("txtEditHours")asTextBox;ddlEditEntity.SelectedValue = "Chastain Center (8755)"; // this doesn't seem to be workingstring entity = ddlEditEntity.SelectedItem.Value;string property = ddlEditProperty.SelectedItem.Value;string description = txtEditDescription.Text;decimal hours =Convert.ToDecimal(txtEditHours.Text);int retval =Queries.UpdateEntity(hmy, entity, property, description, hours);

GridView1.EditIndex = -1;

GetTimeByUser(ddlYear.SelectedValue +

"/" + ddlMonth.SelectedValue);

}


Well, we added databinding support in the 60731 release of the Toolkit. :) Would you mind trying that approach again with the updated Toolkit? Failing that, let me know and I'll have a look. For real this time. :) Thanks!


When upgrading to the latest do all I need to do is swap out the dll, correct?


Yes, but you'll need to swap out the Microsoft.Web.Atlas.DLL as well (if you're not already using the July CTP).


Thanks David I will try this approach today. One final question. Is it necessary to swap out the Script Library as well? Do you guys update the JavaScript code to reflect changes in the dll?

I swapped out my dll's as followed:

AtlasControlToolkit.dll (version 1.0.60731.0)

Microsoft.AtlasControlExtender.dll (version 1.0.60726.0)

Microsoft.Web.Atlas.dll (version 2.0.50727.60725)

And did the following and still get the error:

The CascadingDropDownProperties control with a two-way databinding to field sentity must have an ID.

<asp:TemplateFieldHeaderText="Entity"><EditItemTemplate><asp:HiddenFieldID="hdnEditEntity"runat="server"Value='<%# Bind("sentity") %>'/><asp:DropDownListID="ddlEditEntity"runat="server"CssClass="dropDownList"/><atlasToolkit:CascadingDropDownID="CascadingDropDown2"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditEntity"

SelectedValue='<%# Bind("sentity") %>'

Category="Entity"PromptText="<-- Selected an Entity -->"ServicePath="webservices/ws_Timetracking.asmx"ServiceMethod="GetEntitesText"/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditProperty"ParentControlID="ddlEditEntity"PromptText="<-- Select a Property -->"ServiceMethod="GetPropsForEntitytext"ServicePath="webservices/ws_Timetracking.asmx"Category="Property"/></atlasToolkit:CascadingDropDown></EditItemTemplate>

joee, I've looked into this for some time and discussed the issue with Shawn as well. Unfortunately for your scenario, we're only able to use one-way databinding (i.e., Eval) in Extender Properties declarations. If you want to handle the CascadingDropDown's SelectedValue that comes back from the client, you'll need to do so in code (at least for the time being - fortunately it shouldn't be very much code!). At a very high level, in order to support two-way databinding, ASP.NET looks for a real Control (hence the error you get about needing an ID) and the Extender Properties objects aren't currently Controls themselves.

Sorry for the trouble; I hope this explanation at least makes things clearer.


Hello

I have a CascadingDropDown in a page and need to set its selectedValue based on the values in the querystring. I tried to use the DataBinding event to set the values, but looks like the event is not being raised.

protected void CascadingDropDown1_DataBinding(object sender, EventArgs e)
{
ddMake.SelectedValue = Request.QueryString["make"];
ddModel.SelectedValue = Request.QueryString["model"];
}

Any ideas?

Thanks for the report! I've just fixed this problem for the next Toolkit release with change 3420 in CodePlex:

Method override ExtenderControlBase.OnDataBinding didn't call base.OnDataBinding, so event handlers hooked up to an extender's .DataBinding event weren't getting fired - this change fixes that problem by calling the base class implementation as it should.

If you're able to use the sources from CodePlex, this should work now. Sorry for the trouble!


Thanks David. I guess change 3431 will address my issue as well. Pardon my ignorance, but how do I work off the source code? Do I just need to build and swap out the Web.Atlas and AtlasControlToolkit.dll?
Yes, just download the sources from CodePlex, extract the files somewhere, build the project, and then use the resulting AtlasControlToolkit.dll instead of the one you were formerly using.

So what is the status now regarding to ways binding, e.g. binding a dropdown's selectedvalue to an item in detailsview ?

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:
<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>
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.
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?Smile ) . 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 placed inside an asp:EditItemTemplate.

I tried the cascading dropdownlist when the user clicks on edit on a formview, but I realized from the following error that this will not work:

System.InvalidOperationException: The UpdatePanel 'EditUpdatePanel' was not present when the page's InitComplete event was raised. This is usually caused when an UpdatePanel is placed inside a template.

I also found a previous threadhttp://forums.asp.net/thread/1255759.aspxwhere the respondent confirmed that the updatePanel must be outside of the GridView

Does that mean that theAtlasControlToolkit:cascadingdropdown control cannot be used within any databound templated controls (such as GridView, FormView, Details, etc.)?

I don't believe so. UpdatePanel has "special needs" on the page which is why it probably has this issue. I haven't tried this but I think CascadingDropdownshould work OK - I can't think of why it wouldn't. Can you give it a try and report back?


I think the problem is that theatlasToolkit:CascadingDropDown requires anatlas:UpdatePanel around the dropdownlists otherwise changing the selection in one dropdownlist would not affect the next. But sinceatlas:UpdatePanel cannot be placed within the EditItemTemplate therefore it seems that there is no way to put theatlasToolkit:CascadingDropDown within the EditItemTemplate.

Here I tried 3 scenarios in addition to the one I described in my previous post:

1- The cascadingdropdown lists work if placed within atlas:UpdatePanel outside of an EditItemTemplate:http://www.webswapp.com/codesamples/aspnet20/atlas/cascadingdropdown.aspx

2- The cascadingdropdown lists not working if placed within the EditItemTemplate and the atlas:UpdatePanel outside the FormView. http://www.webswapp.com/codesamples/aspnet20/atlas/cascadingdropdown2.aspx

(On my local PC, a JavaScript popup dialog box comes with the following error: "System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using in configuration or in a page." But when run remotely you do not get that error. The lists just do not display anything)

3- The cascadingdropdown lists not working if placed within the EditItemTemplate and no atlas:UpdatePanel on the page

The source code for all scenario are listed on the demo pages.


CascadingDropDown does not need an UpdatePanel to work - the client-side changes are done in script and the web service requests are async thanks to Atlas. So #3 above is the scerario you probably want. I suspect it's not working for you because your ParentControlID properties are pointing at "CascadingDropDownX", but your DropDown controls are named "ddlYYY". Please try fixing that and let us know how it goes!

Hi David,

Thanks for your help. Your suspicion was right. I had the wrong values for the ParentControlID. Now that I corrected them and got it working within the FormView's EditItemTemplate and the data is being updated upon postback successfuly as shown here: http://www.webswapp.com/codesamples/aspnet20/atlas/toolkit_cascadingdropdown.aspx

I am wondering about the possibility of doing 2 more features to make the function of this control equivalent to the server-side controls:

1- How to set the default values upon loading the EditItemTemplate? (Since I could not use the Bind or Eval statements)

2- In order to prevent flashing of the screen when I submit the FormView, I tried using the Atlas:UpdatePanel around the FormView but I got this error message:

Assertion Failed: Unrecognized tag AtlasControlExtender:ValidationScript


That is so cool!

From above...

1) This is a feature we've added to the refresh, which should be available within the next day or so. When it is, you can just add a "SelectedValue='blah'" to the properties and it'll select that value

2) I'm not sure why you're getting that. In any case, in your extender set "SuppressValidationScript='false'" and it'll preven that guy from even loading.


<atlasToolkit:CascadingDropDownID="CascadingDropDown1"runat="server" SuppressValidationScript="false">

I tried # 2 above but I still get the error. The code is exactly as listed in the link I provided before plus the updatePanel surrounding the FormView

<atlas:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:FormViewID="FormView1"runat="server" .... >

</asp:FormView>

</ContentTemplate>

</atlas:UpdatePanel>


SuppressValidationScript="true"

Ok. The first error (above) does not show up but the next errors (which used to appear after I clicked on cancel) is still repeated for each dropdown list: "Assertion Failed: Unrecognized tag atlasControlToolkit:cascadingDropDownBehavior"


That's often related to the relative position of the controls, the extender, and the UpdatePanel. Some wiggling around of the different items can sometimes solve the problem. If it doesn't - and if the new Toolkit release doesn't help - please let us know.

CascadingDropDown not working within EditItemTemplate in Ajax Beta

I had the cascading drop down working fine inside the EditItemTemplate in a gridview with the previous Atlas CTP release. But now it stopped working with Ajax Beta 1.0. Do I need to do something different to make it work again. I tried placing Gridview.Databind() in Page_Load, but that stopped the gridview from updating back to the database.

<EditItemTemplate>

<asp:DropDownListID="ddlBuEdit"runat="server"/>

<ajax:CascadingDropDownID="ccd1"runat="server"

TargetControlID="ddlBuEdit"

Category="BU"

LoadingText="Loading Data..."

PromptText="Select Business Unit"

ServicePath="getSelectionData.asmx"

SelectedValue='<%# Eval("BusinessUnit") %>'

ServiceMethod="getBU"/>

</EditItemTemplate>

Please see if this is relevant:http://forums.asp.net/thread/1441672.aspx.

CascadingDropDown inside of a repeater

I'm trying to create a CascadingDropDown inside of a repeater, and just can't seem to figure it out.

I have a dropdownlist created within a repeater that should cascade from another dropdownlist that is also generated within the repeater.

The problem that arises from this situation is when I go to set the CascadingDropDownProperties, I get this error:

Object reference not set to an instance of an object.

Description:Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of thecurrent web request. Information regarding the origin and location ofthe exception can be identified using the exception stack trace below.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
AtlasControlToolkit.CascadingDropDown.OnPreRender(EventArgs e) in d:\Depot\Atlas\agility\AtlasControls\MAIN\Src\ControlLibrary\CascadingDropDown\CascadingDropDownExtender.cs:60
System.Web.UI.Control.PreRenderRecursiveInternal() +77
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360


When I go through with the debugger it doesn't break on any line of code, so I'm not totally sure what's causing the error. I have figured out that the problem happens when I set the TargetControlID, because If I comment out that line then It'll work. I'm guessing I'll have the same problems with the ParentControlID, also.

cddpNew.TargetControlID = DropDownListControl.ClientID

Has anyone gotten a Cascading drop down to work within a repeater?Since that didn't work I decided to take another approach, which is to put the CascadingDropDown inside the repeater. This had it's own problem.

When trying to get the control from within the repeater during the function that handles the databinding event for the repeater I get the error:

Value of type 'System.Web.UI.Control cannot be converted to 'AtlasControlToolkit.CascadingDropDownProperties'.

So, no luck this direction either.Sad
In the first case, you probably need to access the CascadingDropDown through the Repeater container (recall that the Repeater creates many instances of its contents). The way ASP.NET implements repeaters is a little tricky, but I think you should be able to accomplish what you want with the right code.

CascadingDropDown in repeater

I have three dropdownlists, three cascadingdropdown extenders, and updatepanel within a repeater. I need to update a label control inside of the updatepanel when the selectedindexchanged event fires for the last dropdown. The problem I'm having is that the event doesn't seem to fire the first time the selectedindex is changed. It works as expected after changing the first time. Anyone have any ideas as to why this is happening. Here is my code.

<asp:RepeaterID="uxPublicationRepeater"OnItemDataBound="PublicationRepeater_ItemDataBound"OnItemCommand="Pub_ItemCommand"runat="server">

<ItemTemplate>

<ajax:CascadingDropDownID="uxPublicationCascading"runat="server"

Category="Publication"

ServiceMethod="GetPublicationsByMarket"TargetControlID="uxPubDropDownList"

ParentControlID="uxMarketDropDownList"PromptText="Select.."LoadingText="Loading.."/>

<ajax:CascadingDropDownID="uxPublicationYearCascading"runat="server"

Category="PublicationYear"PromptText="Select.."LoadingText="Loading.."

ServicePath="~/Services/LookupWebService.asmx"ServiceMethod="GetYearsByPublication"

TargetControlID="uxPublicationDateDropDownList"ParentControlID="uxPubDropDownList"/>

<asp:DropDownListID="uxMarketDropDownList"runat="server"/>

<asp:DropDownListID="uxPubDropDownList"runat="server"/>

<asp:DropDownListID="uxPublicationDateDropDownList"OnSelectedIndexChanged="IndexChanged"AutoPostBack="true"runat="server"/>

<asp:UpdatePanelID="uxUpdatePanel"ChildrenAsTriggers="false"UpdateMode="conditional"runat="server">

<ContentTemplate>

<asp:LabelID="uxLabel"runat="server"/>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="uxPublicationDateDropDownList"EventName="SelectedIndexChanged"/>

</Triggers>

</asp:UpdatePanel>

</ItemTemplate>

</asp:Repeater>

Thanks for the help.

Have you taken a look at the sample?http://www.asp.net/AJAX/Control-Toolkit/Live/CascadingDropDown/CascadingDropDown.aspx

This could be related to EventValidation (see http://www.asp.net/AJAX/Control-Toolkit/Live/Walkthrough/CCDWithDB.aspx specfically:"Finally, in order for the values to be submitted, EventValidation needs to be disabled for the page. EventValidation ensures that the values in each control match the values that were present when the page was rendered, but since these drop downs are populating on the client side, this is never true.")

-Damien


I tried turning event validation off and still no good. The event fires the first time if the controls are outside of the repeater, but doens't fire until the second time when inside the repeater.


No one else has ran into this problem? If I take the cascadingdropdown extender out, the events fire correctly. Just to recap, dropdownlists in a repeater, selectedindexchange event fires correctly. Dropdownlists and cascadingdropdown extenders inside a repeater the event doesn't fire until the second time the selectedindex is changed. If anyone is interested I have a small sample app that illustrates the problem.


c.barnes01:

No one else has ran into this problem? If I take the cascadingdropdown extender out, the events fire correctly. Just to recap, dropdownlists in a repeater, selectedindexchange event fires correctly. Dropdownlists and cascadingdropdown extenders inside a repeater the event doesn't fire until the second time the selectedindex is changed. If anyone is interested I have a small sample app that illustrates the problem.

Hi,

I'd like to see your small sample, it will be preferred to use NorthWind database or a fake data source built in code.


Here is a small app that illustrates the problem.

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" EnableEventValidation="false" Inherits="_Default" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:Repeater ID="uxTestRepeater" OnItemDataBound="Repeater_DataBound" runat="server"> <ItemTemplate> <cc1:CascadingDropDown ID="uxCountriesCascading" Category="Countries" runat="server" ParentControlID="uxCountryDropDownList" TargetControlID="uxStatesDropDownList" LoadingText="Loading.." PromptText="Select.." ServiceMethod="GetScopedStates" /> <asp:DropDownList ID="uxCountryDropDownList" runat="server" /> <asp:DropDownList ID="uxStatesDropDownList" AutoPostBack="true" OnSelectedIndexChanged="SelectedIndex_Changed" runat="server" /><br /> <asp:UpdatePanel ID="uxUpdatePanel" runat="server"> <ContentTemplate> <asp:Label ID="uxStateLabel" runat="server" Text="Select a State" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="uxStatesDropDownList" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> <hr /> </ItemTemplate> </asp:Repeater> </div> </form></body></html>

using System;using System.Collections;using System.Collections.Generic;using System.Collections.Specialized;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.Services;using System.Web.Script.Services;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using AjaxControlToolkit;public partialclass _Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) {if (!Page.IsPostBack) {this.uxTestRepeater.DataSource = GenerateRepeaterDataSource();this.uxTestRepeater.DataBind(); } }private List GenerateRepeaterDataSource() { List toReturn =new List(); toReturn.Add(new MyClass(1,"Chris"));return toReturn; }protected void Repeater_DataBound(object sender, RepeaterItemEventArgs e) { DropDownList countryDropDownList = e.Item.FindControl("uxCountryDropDownList")as DropDownList; countryDropDownList.DataSource = GenerateCountries(); countryDropDownList.DataTextField ="Value"; countryDropDownList.DataValueField ="Key"; countryDropDownList.DataBind(); }private Dictionary<int,string> GenerateCountries() { Dictionary<int,string> toReturn =new Dictionary<int,string>(); toReturn.Add(1,"USA"); toReturn.Add(2,"Canada"); toReturn.Add(3,"Mexico");return toReturn; }protected void SelectedIndex_Changed(object sender, EventArgs e) { DropDownList stateDropDown = senderas DropDownList; Label stateLabel = stateDropDown.NamingContainer.FindControl("uxStateLabel")as Label; stateLabel.Text = stateDropDown.SelectedItem.Text; } [WebMethod] [ScriptMethod]public static CascadingDropDownNameValue[] GetScopedStates(string knownCategoryValues,string category) { CascadingDropDownNameValue[] toReturn =null; StringDictionary values = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);if (values.Count == 1) {string key = values["undefined"];switch (key) {case"1": toReturn = GetStatesForUsa();break;case"2": toReturn = GetStatesForCanada();break;case"3": toReturn = GetStatesForMexico();break;default:break; } }return toReturn; }public static CascadingDropDownNameValue[] GetStatesForUsa() { CascadingDropDownNameValue[] toReturn =null; toReturn =new CascadingDropDownNameValue[5]; toReturn[0] =new CascadingDropDownNameValue("SC","1"); toReturn[1] =new CascadingDropDownNameValue("GA","2"); toReturn[2] =new CascadingDropDownNameValue("NY","3"); toReturn[3] =new CascadingDropDownNameValue("FL","4"); toReturn[4] =new CascadingDropDownNameValue("NC","5");return toReturn; }public static CascadingDropDownNameValue[] GetStatesForCanada() { CascadingDropDownNameValue[] toReturn =null; toReturn =new CascadingDropDownNameValue[5]; toReturn[0] =new CascadingDropDownNameValue("Saskatchewan","1"); toReturn[1] =new CascadingDropDownNameValue("Alberta","2"); toReturn[2] =new CascadingDropDownNameValue("British Columbia","3"); toReturn[3] =new CascadingDropDownNameValue("Nunavut","4"); toReturn[4] =new CascadingDropDownNameValue("Yukon","5");return toReturn; }public static CascadingDropDownNameValue[] GetStatesForMexico() { CascadingDropDownNameValue[] toReturn =null; toReturn =new CascadingDropDownNameValue[5]; toReturn[0] =new CascadingDropDownNameValue("Hidalgo","1"); toReturn[1] =new CascadingDropDownNameValue("Veracruz","2"); toReturn[2] =new CascadingDropDownNameValue("Puebla","3"); toReturn[3] =new CascadingDropDownNameValue("Durango","4"); toReturn[4] =new CascadingDropDownNameValue("Sonora","5");return toReturn; }}public class MyClass{private int id;public int ID {get {return id; }set { id =value; } }private string name;public string Name {get {return name; }set { name =value; } }public MyClass(int id,string name) {this.id = id;this.name = name; }}

I still haven't found a solution to this yet. Anyone have any suggestions?

Thanks


Bump


What is the full type name of the toReturn( List toReturn =new List();) object?


It should have been, List<MyClass> toReturn = new List<MyClass>();

thanks


I looked into it through, and found out that the reason is because the items are filled on client side.

1. On the first request( when isPostback is false ), there is no items in DDLState.

2. DDLState is filled when the page has been rendered in the browser

3. Select an item in the DDL to start a postback

4. The DDL tries to find the currentIndex( it's -1 since it can't be found ) and compares it with previousIndex( it's -1 since there is no item previously ) to see if a selectedChanged event should be fired. And it won't be fired because they are equal

5. On the second request, the previously posted item is kept in ViewState and subsequently added into DDLState's items collection

6. The previously index is 0 because the only item currently in DDLState matches the previous value. And currently posted item's value still doesn't exist, so currentIndex is -1. They are not equal, thus the SelectedIndexChanged event is fired.



Thanks for looking into the problem. It's weird that it works when not in a repeater.

CascadingDropDown In a user control

Hi,

I'm trying to use the cascading dropdown control inside the edit template of a form view control which is wraped inside a user control. The cascading dropdown obtains its data from a database. Their is no problem geting the data. The issue is when I go to set the selected value of the cascading dropdown to a value in the FormView_databound event handler, the selected value is does not get set, it shows "Please Select" which is the value I set in the begining.

Please help

Please try your scenario with the recently available61106 release of the Toolkit (and ASP.NET AJAX Beta 2). If the problem persists, then please reply with acomplete, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!

CascadingDropDown in a datagrid

Hello,

Is it possible to populate a dropdownlist inside a datagrid, which will repeat itself for as many rows their are inside the datagrid? Any example code would be appreciated. Thanks.

Yes, I'd expect this to work. If you run into problems, please let us know!