Showing posts with label dropdown. Show all posts
Showing posts with label dropdown. Show all posts

Wednesday, March 28, 2012

Linking two DropDowns via Atlas?

I have looked at the Atlas controls (January 2006 Release)

What i would like to know is, say i make a dropdown, place it in a
update panel, then link it all up to some datasource, add a trigger to
the page to populate the dropdown, e.g. a button (i get this going
np.)

Now what i would like to do is add a second dropdown and have it
update when i make a selection from the first dropdown, this i can not
get to work.

In the Atlas controls smart tag to add the triggers i only get to see
controls on the page which are not located within a updatepanel,

So i tried to just write then trigger manually, this produced no
visible error on the page, but the second dropdown is not populating
either?

Is this along the lines you are looking to do?

<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />

<atlas:UpdatePanel runat="server" ID="UpdatePanel1" Mode="Conditional" >
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="foo" Value="foo" />
<asp:ListItem Text="bar" Value="bar" />
</asp:DropDownList>
</ContentTemplate>
</atlas:UpdatePanel>
<hr />
<atlas:UpdatePanel runat="server" ID="Computer" Mode="Conditional">
<Triggers>
<atlas:ControlEventTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</ContentTemplate>
</atlas:UpdatePanel>


No thats it exactly, but thank youBig Smile [:D]

Did you have to manually type the second trigger (to populate dropdown2)?

What i was wondering was,

Say you had a button, when pressed, it fired a trigger to populate the first Dropdown1 (Foo, Bar)

Then I wanted to be able to make a selection from the Dropdown1 and then get data to populate Dropdown2,

by running a SQL Query which took the selected item from Dropdown1 as a param.


Made a Typo sorry

I said in last post

No thats it exactly, but thank you

I mean

No thats not exactly it, but thank youWink [;)]


Sad [:(] Example, this does not update the second "Dropdown2", both controls are contained in the 1 UpdatePanel

<atlas:UpdatePanel runat="server" ID="UpdatePanel1" Mode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem Text="foo" Value="foo" />
<asp:ListItem Text="bar" Value="bar" />
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="Button1" EventName="Click" />
<atlas:ControlEventTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</atlas:UpdatePanel>

Smile [:)] This example does, but you need to have 2 UpdatePanels

<atlas:UpdatePanel runat="server" ID="UpdatePanel1" Mode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem Text="foo" Value="foo" />
<asp:ListItem Text="bar" Value="bar" />
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</atlas:UpdatePanel>
<hr />
<atlas:UpdatePanel runat="server" ID="Computer" Mode="Conditional">
<Triggers>
<atlas:ControlEventTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</ContentTemplate>
</atlas:UpdatePanel>


in this example i have the script manager and updateprogress atlas controls on a master page, thus i gane share them around between different pages in the test site this has the button control out site which triggers the population of the dropdown1 control, then making a selection from the dropdown1 populates dropdown2 This is what i wanted to do in the first post i made.

Client side code:

<%@.PageLanguage="VB"MasterPageFile="~/MasterPage.master"AutoEventWireup="false"CodeFile="Default.aspx.vb"Inherits="_Default"title="Untitled Page" %>

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

<div>

<asp:ButtonID="Button1"runat="server"Text="Button"/>

<atlas:UpdatePanelrunat="server"ID="UpdatePanel1"Mode="Conditional">

<ContentTemplate>

Dropdown 1

<asp:DropDownListID="DropDownList1"runat="server"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"

AutoPostBack="True">

<asp:ListItemText="foo"Value="foo"/>

<asp:ListItemText="bar"Value="bar"/>

</asp:DropDownList><br/>

Dropdown 2

<asp:DropDownListID="DropDownList2"runat="server">

</asp:DropDownList>

</ContentTemplate>

<Triggers>

<atlas:ControlEventTriggerControlID="Button1"EventName="Click"/>

<atlas:ControlEventTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/>

</Triggers>

</atlas:UpdatePanel>

</div>

</asp:Content>

Server Side code:

PartialClass _Default

Inherits System.Web.UI.Page

Dim dsAs Data.DataSet

Dim obsAs Data.DataTable

Dim defAs Data.DataTable

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

ds =New Data.DataSet

obs =New Data.DataTable

def =New Data.DataTable

ds.ReadXml("url to my xml datasopurce here")

def = ds.Tables("data-def")

obs = ds.Tables("obs")

EndSub

ProtectedSub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)

Dim xmldocAsNew System.Xml.XmlDocument

xmldoc.LoadXml(ds.GetXml)

Dim obsAs System.Xml.XmlNodeList = xmldoc.SelectNodes("weather-observations/product/group/obs")

Dim xmlEAs System.Xml.XmlElement

ForEach xmlEIn obs

If xmlE.Attributes.Item(4).Value =Me.DropDownList1.SelectedItem.TextThen

Me.DropDownList2.Items.Clear()

Dim xmlEnumeratorAs IEnumerator

xmlEnumerator = xmlE.ChildNodes.GetEnumerator()

xmlEnumerator.Reset()

While xmlEnumerator.MoveNext

Dim eleAs System.Xml.XmlElement

ele = xmlEnumerator.Current

Me.DropDownList2.Items.Add(ele.Attributes.Item(0).Value &" : " & ele.FirstChild.Value)

EndWhile

EndIf

Next

EndSub

ProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click

Me.DropDownList1.DataSource = obs

Me.DropDownList1.DataTextField ="station"

Me.DropDownList1.DataBind()

EndSub

EndClass


In the latest rev of Atlas, controls within the UpdatePanel should not require an explicit trigger as this is implied. If you want the UpdatePanel to refresh based on controls outside the UpdatePanel then the trigger is required. This therefore means that controls outside the UpdatePanel are traditionally post-back controls unless wired to triggers.The simplified example (#1) therefore should be OK without the DropDownList trigger. The Click handler of the button could be used to drive population of drop-down list 1. I'll try and work on a server binding sample for you.


Odd -- I was trying my own code (pretty much the exact code as above) and I get an "Unknown Error". I tried this code, and I get the same error. Its a pretty vague error, but any ideas as to where I should begin to look?

Thanks!


I checked this code ( the good one ) and put one breakpoint at first line in page load method. Every time I changed the option in the DropDownList and the application stopped on the breakpoint.

I don't know if this control (UpdatePanel ) works in this way or is something wrong in the code but I supossed that the panel is updated with an asynchronous server call. Could anybody explain me the functionality of the control?

Thanks.


The Code is Good But Doesnt Work ...

Please help ..

Monday, March 26, 2012

ListsearchExtender AutoPostback not firing

I have a Dropdown list control with autopostback = true. I am extending the control with the ListsearchExtender control. When I search the list and hit tab or enter the autopostback works as expected. But if I search the list and then click on the desired list item with the mouse it does not autopostback. I am using version 10920 of the toolkit.

Thanks.

Hi Jdclark,

We noticed that you had postanother thread before. If you have further questions, please feel free to discuss us in theorignal thread.

Best regards,

Jonathan

ListsearchExtender AutoPostback not firing

I have a Dropdown list control with autopostback = true. I am extending the control with the ListsearchExtender control. When I search the list and hit tab or enter the autopostback works as expected. But if I search the list and then click on the desired list item with the mouse it does not autopostback. I am using version 10920 of the toolkit.

Thanks.

Hi Jdclark,

I have wrote a sample and it works on my machine. My version is V11119 which is the latest. But as far as I know, there is no such issue reported on Codeplex. So I suggest that you should remove all the unnecessary parts and have a test.

<asp:DropDownList ID="DropDownList1" runat="server" Width="100px" AutoPostBack="true" />
<ajaxToolkit:ListSearchExtender ID="ListSearchExtender2" runat="server"
TargetControlID="DropDownList1" PromptCssClass="ListSearchExtenderPrompt">
</ajaxToolkit:ListSearchExtender>

C#:

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ListBox1.DataSource = GetWordListText();
ListBox1.DataBind();
DropDownList1.DataSource = GetWordListText();
DropDownList1.DataBind();
}

If it doesn't work, please feel free to let me know with asimple repro.

Best regards,

Jonathan


Hi Jonathan,

Thanks for the response. I downloadded V1119 and created a simple page. But I still have the same problem.

If I type to search and hit enter it works.
If I change focus it works.
If I dont type to search and just use the mouse to select it works.
If I type to search and use the mouse to click on any item other than the one highlighted by the search it works.

But If I type to search and click on the one highlighted by the search it does not fire the postback until loosing focus.

I know the easiest thing to do is type and hit enter, but I know if I use this feature in my application, inevitably someone will try to click and then complain it doesn't work.

Here is my page code:

<body>
<form id="form1" runat="server">
<div>
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<asp:DropDownList ID="DropDownList1" runat="server" Width="100px" AutoPostBack="true">
</asp:DropDownList>
<ajaxToolkit:ListSearchExtender ID="ListSearchExtender1" TargetControlID="DropDownList1" runat="server">
</ajaxToolkit:ListSearchExtender>
</div>
</form>
</body>

Here is my code behind code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
DropDownList1.Items.Add(New ListItem("Apple", "Apple"))
DropDownList1.Items.Add(New ListItem("Orange", "Orange"))
DropDownList1.Items.Add(New ListItem("Banana", "Banana"))
DropDownList1.Items.Add(New ListItem("Pear", "Pear"))
DropDownList1.Items.Add(New ListItem("Pinapple", "Pinapple"))
DropDownList1.Items.Add(New ListItem("Grapes", "Grapes"))
End If
End Sub

Thanks for your help.


Hi JdClark,

Yes, I have reproduced your issue on my machine now. However, I think it is a design pattern rather than an issue.When we type the search text , the DropDownExtender will change its selectedIndex. DropDownExtender won't postback when it select the orignal item. So that's why the page don't postback in your situation. To fix this, ListSearchExtender attach onblur event to the DropDownExtender and it will force the page postback. Here is the code snippet.

 _onBlur : function() { /// <summary> /// Handle the Select's blur event /// </summary> this._disposePopupBehavior(); // Remove the DIV showing the text typed so far var promptDiv = this._promptDiv; var element = this.get_element(); if(promptDiv) { this._promptDiv = null; element.parentNode.removeChild(promptDiv); } if(!this._raiseImmediateOnChange && this._focusIndex != element.selectedIndex) { this._raiseOnChange(element); } }

We cannot find a better way for your situation, so I suggest that you should post your issue as a suggestion toCodePlex so that our developers will evaluate

it seriously and take it into consideration when designing the future release of product.Thanks

Best regards,

Jonathan


Hi Jonathan,

Thank you very much for your answer. Pardon my ignorance, but how do I attach the above code to the onblur event of the Dropdown control?

Thank you.


Hi Jdclark,

It is already contained in the AJAX Control Toolkit's source code. Also the onblur event has been attached to the Extender yet.Based on my research , I was failed to find out a better acceptable formula unless we modify its source code.

Best regards,

Jonathan

ListSearchExtender (with a CascadingDropdownExtender)

Hi,

I'm using the ListSeachExtender as was intended, on a dropdown looking up from the list and finding based on what I've typed. The problem I'm having is that the OnChange event is never firing so I'm not getting the desired result when in fact the selected item is changing. I'm using this in combination with the CascadingDropDown extender but because the OnChange isn't firing my second DDL is not being populated with the correct results. Is there some way I can fire the OnChange event to get the desired result?

Thanks,
Dan

It should be fired when the element is selected by the ListSearch behavior in the else block. Please open awork item to track this. Thanks!

// If nothing is found then stick with the current option

if(selectedIndex == -1) {

// Need this because firefox has aleady changed the current option based on the character typed

this._newIndex =this._originalIndex;

}else {// Otherwise move to the new option

element.selectedIndex = selectedIndex;

this._newIndex = selectedIndex;

}


I've added a work item: http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=8771

ListSearchExtender it seems that onchange event is not fired on DropDown

I'm using ListSearchExtender and seems that onchange is not fired when you type in DropDown. Is it a known bug? Is there any work around?

This is a known issue and we are planning to fix it. You could work around it by changing the code to fire the event in _searchForTypedText after the selected index has been set. Thanks.
Thanks. I'll just wait for fix. Is new version of Ajax Toolkit coming in the beging of april?

Personally, I'd rather put it in _onKeyPress, like this:

if

(e.charCode == Sys.UI.Key.enter || e.charCode == Sys.UI.Key.tab) {

element.onchange(

this);

}

Or _onBlur


Sorry... better yet.

In _onBlur after removing the prompt div, you can use this:

if

(this._originalIndex !=this._newIndex) {

element.onchange(this);

}


My way to fire the onChange is to call the same javascripts function in bothonChange andonKeyUp:

<asp:ListBoxid="ListBox1"runat="server"onChange="DoSomething(this)"onKeyUp="DoSomething(this)"></asp:ListBox>

<cc1:listsearchextenderid="ListSearchExtender1"runat="server"TargetControlID="ListBox1"PromptCssClass="listSearch"></cc1:listsearchextender>


The list box extender now fires the change event and you should not need to workaround this anymore. Please download the latest version of the Toolkit which contains this fix.

Wednesday, March 21, 2012

Loading all dropdowns with cascading dropdown extender

Since the cascading dropdown extender loads all dropdowns with a webservice, is it faster to load all dropdowns with this even if cascading is not needed?

In other words, is it faster to load a large (100+) dropdown with the cascading dropdown extender than doing it on the page load?

Hi Red_bull_n_vodka,

red_bull_n_vodka:

Since the cascading dropdown extender loads all dropdowns with a webservice, is it faster to load all dropdowns with this even if cascading is not needed?

In other words, is it faster to load a large (100+) dropdown with the cascading dropdown extender than doing it on the page load?

Actually, CascadingDropDown will call its WebService as soon as it is initialized. So I don't think it will be prominent faster in your situation. To speed up the response times , I think you should pay more attention to WebService rather than the client implementation.For example, cache and connection pool etc.

I hope this help.

Best regards,

Jonathan