Showing posts with label behavior. Show all posts
Showing posts with label behavior. Show all posts

Wednesday, March 28, 2012

Programatically Adding an AutoCompleteExtender & AutoCompleteProperties

This is from the documentation:

To extend a text box with auto-completion behavior programmatically, add an AutoCompleteExtender control to your ASP.NET Web page, and use theServicePath andServiceMethod properties to specify the Web method that returns the item list. Then for each text box that you want to add the auto-completion behavior to,add anAutoCompleteProperties server control to theControls collection of the AutoCompleteExtender. The AutoCompleteProperities component enables you to specify the target control the extender should link to and to override the ServicePath and ServiceMode setting for individual controls.

So am I to understand that I add an AutoCompleteProperties instance to the AutoCompleteExtender.Controls collection?

When I try that I get this message in VS2005:

Value of type 'Microsoft.Web.UI.Controls.AutoCompleteProperties' cannot be converted to 'System.Web.UI.Control'.

hello.

well, you just need to add them as child elements of the control since it'll automaticatically parse those elements and add them to the targetproperties property.


...forgive me for my ignorance, but how exactly is that accomplished? Can you provide a brief example?

Thanks! :)


Dim autoComplete as New AutoCompleteExtender()
Dim props as New AutoCompleteProperties()
props.TargetControlID = "txt_suggestion"
props.ServiceURL = "/WebServices/Service.asmx"
props.ServiceMethod = "GetSuggestions"
autoComplete.TargetProperties.Add(props)
Page.Controls.add(autoComplete)

Hey that worked! Thanks!

I didn't know about the AutoCompleteExtender.TargetProperties.Add method, I was trying to add it to the controls collection of the AutoCompleteExtender.

FYI - The ServiceURL property in the above code is supposed to be ServicePath (at least in the July 06 release).

Saturday, March 24, 2012

Question about DropDownList behavior inside an UpdatePanel

Hi,

I have an application that has two DropDownLists on a page. The first is just a plain ASP DropDownList; the second is an ASP DropDownList inside an UpdatePanel. The page also contains a label inside a second UpdatePanel.

When the item in the first DropDownList is changed, the second DropDownList is populated. When the item in the second DropDownList is changed, the Label's text is changed.

I have noticed that when the first DropDownList changes, the second DropDownList "flickers" as it populates. When I select a value in the second list, the label updates as it should, but the second DropDownList again flickers, as if it is also being refreshed. Both UpdatePanels have UpdateMode="conditional" set.

My question is whether this is normal behavior on the second DropDownList, since it is inside an UpdatePanel, or do I have something set wrong? It's a minor issue, but kind of annoying since I would not expect to see any kind of refresh when changing a value in the second DropDownList.

I have included a simple example which shows what I'm talking about. Thanks as always for your help!

<%@dotnet.itags.org.PageLanguage="vb"AutoEventWireup="false"CodeBehind="Default.aspx.vb"Inherits="DropDownTest._Default" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server"/>

<div>

<ASP:DROPDOWNLISTid="DropDownList1"autopostback="true"runat="server"width="110px"></ASP:DROPDOWNLIST>

<br/><br/><br/><br/><br/><br/>

<ASP:UPDATEPANELid="UpdatePanel1"runat="server"updatemode="conditional">

<CONTENTTEMPLATE>

<ASP:DROPDOWNLISTid="DropDownList2"autopostback="true"runat="server"width="110px"></ASP:DROPDOWNLIST>

</CONTENTTEMPLATE>

<TRIGGERS>

<ASP:ASYNCPOSTBACKTRIGGERcontrolid="DropDownList1"eventname="SelectedIndexChanged"/>

</TRIGGERS>

</ASP:UPDATEPANEL>

<br/><br/><br/><br/><br/><br/>

<ASP:UPDATEPANELid="UpdatePanel2"runat="server"updatemode="conditional">

<CONTENTTEMPLATE>

<ASP:LABELid="Label1"runat="server"text="Label"></ASP:LABEL>

</CONTENTTEMPLATE>

<TRIGGERS>

<ASP:ASYNCPOSTBACKTRIGGERcontrolid="DropDownList2"eventname="SelectedIndexChanged"/>

</TRIGGERS>

</ASP:UPDATEPANEL>

</div>

</form>

</body>

</html>

PartialPublicClass _Default

Inherits System.Web.UI.Page

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

IfNot IsPostBackThen

Me.DropDownList1.Items.Clear()

Dim objListItemAs ListItem

objListItem =New ListItem

objListItem.Text = 1

Me.DropDownList1.Items.Add(objListItem)objListItem =New ListItem

objListItem.Text = 2

Me.DropDownList1.Items.Add(objListItem)

objListItem =New ListItem

objListItem.Text = 3

Me.DropDownList1.Items.Add(objListItem)

EndIf

EndSub

PrivateSub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles DropDownList1.SelectedIndexChanged

Me.DropDownList2.Items.Clear()

Dim objListItemAs ListItemobjListItem =New ListItem

objListItem.Text = 9

Me.DropDownList2.Items.Add(objListItem)

objListItem =New ListItem

objListItem.Text = 8

Me.DropDownList2.Items.Add(objListItem)objListItem =New ListItem

objListItem.Text = 7

Me.DropDownList2.Items.Add(objListItem)

EndSub

PrivateSub DropDownList2_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles DropDownList2.SelectedIndexChanged

Me.Label1.Text =Me.DropDownList1.SelectedValue +Me.DropDownList2.SelectedValue

EndSub

EndClass

Does this happen in both FF and IE6/7?


Definitely in IE6, as that's my default right now. I tried Firefox, and it does not seem to have this issue.

I also noticed that in IE6, when I select the item in the first list, the item is highlighted (dark blue background) until I move focus. When I select an item in the second list, the highlighting is removed. This could simply be because the focus shifted to the label. Neither list stays highlighted in Firefox.

So, it appears that it may be an IE quirk. Has anyone else seen this issue or found a work around? I should be getting IE7 on my PC in the next week or two, so maybe that will solve it!


IE6 blows. I know - Shocking news!

Try it out on IE7 and see if that fixes your problem.

I realize that some of the world is still using IE6, some can't even upgrade to 7 (ie. Win2K users) but I hate coding for that browser.


You should set the property of the UpdatePanel named "UpdatePanel2":updatemode="all"