Showing posts with label box. Show all posts
Showing posts with label box. 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).

Monday, March 26, 2012

Programmatically trigger modal popup

I want to write a page that checks for a cookie via Javascript and then possibly opens a modal dialog box. How do I trigger the modal popup via client side javascript?

I saw the example that comes on the modal dialog that sample page, however that works with a client side event such as a click. Can I do it without listening for an event?

Hi theregit,

In the javascript where you check the cookie, you can trigger a button.

That button's click event can then be another javascript that opens a modal window.

Trigger the button like:
var myButton = document.getElementById('myButton');
myButton.click();

Is this an answer to your question?
if you have comments/remarks/questions .. please do so!

Kind regards
Wim


Try this ,

Show and Hide ModalPopupExtender from JavaScript

Hope this helps


Phanatic,

Thank you sooo much for that post. I was having the problem with the 'null' is null or not an object error. Once I used the pageLoad() method it worked great.

Saturday, March 24, 2012

Question About AutoComplete

Hello,

I have setup a page containing two text box which utilize the AutoComplete Extension and work perfectly (thanks to the video helps), but I would like to extend this a bit. I would like to use the variable that had been put into the first text box, to restrict what is displayed in the second auto complete. Basically, once I am within my autocomplete.asmx file, how to I get the variable of what was in the first text box to pass into my stored procedure?

Thanks,

Chris

What you want to do is use the contextKey parameter. It's described in thedocumentation for the extender.


Hrm, this is very close, but I still do not see how to assign the text, or a variable, to the ContextKey? I can see how to pass a static piece of text in, which I have had success with, but have not had to much luck with the variable.

Thanks,

Chris


You can use $find('AutocompleteExtenderClientID').set_contextKey() to set that on the client side. So, you'd want to use $addHandler to handle the context textbox's onchange event and update the autocomplete extender's contextKey with the textbox's new value.

Is this what you were talking about? I get some errors when I try to compile it. Also, is there a way to Prepend the text it is going to set?

Thanks so much,

Chris

1<asp:TextBox ID="PortName" runat="server" OnTextChanged=$find('AutoCompletePortName').set_contextKey()></asp:TextBox>23<cc1:AutoCompleteExtender ID="AutoCompletePortName" runat="server" TargetControlID="PortName" ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList" MinimumPrefixLength="3" CompletionSetCount="5" ContextKey=$addHandler UseContextKey=True>4 </cc1:AutoCompleteExtender>5


You might be able to do this, but I haven't tested it:

<cc1:AutoCompleteExtender ID="AutoCompletePortName" runat="server" TargetControlID="PortName" ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList" MinimumPrefixLength="3" CompletionSetCount="5" ContextKey="$get('<%= PortName.ClientID%>').value" />

If it works, that's going to be the easiest way to do it. Also, you don't have to explicitly set UseContextKey. If a ContextKey is specified, it will automatically use it.

$addHandler is a little bit more complicated than that. You can see a few examples of using it here:http://encosia.com/2007/11/15/exploring-one-of-ms-ajaxs-often-overlooked-features/