Wednesday, March 28, 2012

Disable Autocomplete extender in code

Is there any way to disable an autocompleteextender?

I have an autocompleteextender that works fine with a textbox but I need to hide that textbox. When I hide it, a javascript exception is thrown because the atlas code can't find the control. What should I do to disable the autocompleteextender in code?

Thanks

I was using this code:

foreach

(AutoCompleteProperties propin AutoCompleteExtender1.TargetProperties) {

prop.Enabled =

false;

}

But it didn't work. However with this it works:

AutoCompleteExtender1.TargetProperties.Clear();

Probably there's a bug somewhere because I think what I was doing should be enough.


hello.

how are you hiding the textbox? i'm guessing that you're setting the visible property to false...unfortunatelly, it looks like the xml script willnot be rendered itht ie enabled property is set to false. you can try to set both the visible and enabled properties of the associated textbox controls to false and this should stop the generation of the xml-script...


It is inside a table row so I set the table row to runat=server and set visible = false to the table row.

I have just tried setting the textbox enable and visible properties to false but it still doesn't work. I think that the correct behaviour should be not to render the xml-script related to the autocomplete textbox when the associated TargetProperty is not enabled.


hello again.

hum...after looking at what's going on, i think that the problem is that the behavior is being registered even when the control is not visible. you can change this by building your own completeextender with code similar to this one:

namespace

LA

{

publicclassBetterAutoCompleteExtender :AutoCompleteExtender

{

protectedoverridevoid OnPreRender(EventArgs e)

{

WebControl ctl =this.NamingContainer.FindControl(this.TargetProperties[0].TargetControlID)asWebControl;if ( ctl !=null && ctl.Visible &&this.TargetProperties[0].Enabled )

{

base.OnPreRender(e);

}

}

}

}

hope this helps (btw, you should open a bug report by adding a new post to the forum and redirect them to this post to get more info about the problem - don't forget to add the [BUG] word on the title).


Thanks Luis.

With that it works properly.

I'll add a new post with the bug.


Hello,

I'm attempting to put the autocomplete extender in a tabbed form. Is there a way to disable the autocomplete when the style of the div layer that the textbox is in gets set to style="display:none"?

Thanks,
Emilie

hello.

hum...in your scenario, you shouldn't need to disable it because if you're setting the display style, that means that all the elements will be loaded and you won't get errors when searching for them...


Here's the simple sample I'm working with:

<body>
<form id="Form1" runat="server">
<atlas:ScriptManager id="AtlasPage1" runat="server" />

<div style="display:none">
<asp:TextBox ID="TextBox1" runat="server"/>
</div>

<Atlas:AutoCompleteExtender runat="server" ID="autoComplete2">
<Atlas:AutoCompleteProperties TargetControlID="TextBox1"
Enabled="True" ServicePath="AutoCompleteService.asmx"
ServiceMethod="GetWordList"
minimumprefixlength="1" />
</Atlas:AutoCompleteExtender>
</form>
</body
Right now it gives me an "invalid argument" exception and cannot find the source code to break to.
However, if I remove style="display:none" from the div, it works fine.
I ran it again this morning and this time it was able to break to the line of code that was failing. In the Webresource.axd file there's a line

completionListStyle.width = (elementBounds.width - 2) + 'px';

But when the div is set to display:none, elementBound.width (referring to the width of the textbox) is 0.

Anyone have ideas on how to get around this?
I'm having the same problem here: when display: none is set, the autocompleteextender throws up an error.

Is there a workaround for this yet?

any news on this one, I have the same problem?

Andy

No comments:

Post a Comment