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

Disable Atlas things at runtime

I've got a form i am trying to create that if:

An administrator is logged in, a textbox with an AutoCompleteExtender (and TextWaterMark control as well) is available for the Admin to search for companies to look at data for

If it's a company logged in, i want to hide/disable this textbox and instead give them a dropdownlist of their assigned company (or companies) and not allow them to search for companies outside of them

the problem i am running into is that when i set the textbox to "visble = false", that causes Atlas to throw an error "Assertion Failed, could not find HTML element blah blah blah"...

I thought i'd be sneaky and instead of saying:
txtCompany.Visible = False

I instead said in the code
txtCompany.Style.Add("display", "none")

but that still errored, althought this time just a "runtime error has occured"

How can i simply say in code:

"If i am not an administrator, turn off the textbox, autocomplete, and watermark"

I'd probably put the entire textbox (atlas update panel included) inside a usercontrol, and show and hide the usercontrol accordinly.
Excellent suggestion and appears to be doing exactly what i want it to do......

Disable Atlas for a Specific Browser

My website was having a specific problem with Safari that required me to disable partial rendering on that browser.

I am currently using an HTTP module to detect that browser and turn off partial rendering, but I feel like this is something that I should be able to do in a *.browser file.

Is there a way using a .browser file to disable atlas for a specific browser?

hello.

well, if i recall correctly, browser files defined the known characteristics of a browser and yuo'll not be able to do that with a file of that type.


Can you please post the code that you're using for the detection. That would save some time ...

Thx
dB.


Ok, it's pretty simple. Again, I am using this in an HTTP module so it always runs:

If HttpContext.Current.Request.UserAgent.Contains("Safari")Then
Dim smAs ScriptManager =CType(CType(sender, Page).Master.FindControl("ScriptManager1"), ScriptManager)
sm.EnablePartialRendering =False
EndIf

I was just thinking that if I could somehow add something to the browsers file that said Safari wasn't capable of using Atlas (by disabling XMLHttpRequest or otherwise), it would be more efficient than what I am doing now.

If you are curious why I am doing this, it is because I am experiencing a bug with LinkButtons, with Atlas, in Safari. I posted a question about that first, butno one had any answer.

disable an updatepanel during asynch callback?

I have an UpdatePanel on a page, and within the UpdatePanel are a GridView and a Button that updates the GridView when clicked. I click the Button, a couple of seconds later the asynch callback returns and the GridView is re-rendered on the screen. Great. Now, what I would like to do is hook into the beginRequest and endRequest events of the client-side PageRequestManager and add a couple of functions that will replace the inner html of whatever UpdatePanel is making the callback request with a "Please Wait..." message while the callback is processing so that the user cannot change anything within the UpdatePanel until the callback is finished. What I can't figure out how to do is get a client-side reference to the UpdatePanel that initiated the current ajax callback. The UpdateProgress control is very close to what I'm trying to achieve, except that it doesn't "hide" its associated UpdatePanel.

Anybody have any ideas?

My recommendation would be to use the UpdateProgress control, and style it such that it covers the UpdatePanel. That would be easiest.

If you want to go ahead and hook beginRequest/endRequest, to answer your question about determining which UpdatePanel contains the control causing the postback, take a look at the JavaScript behind the UpdateProgress control, specifically this function:

 function Sys$UI$_UpdateProgress$_handleBeginRequest(sender, arg) { var curElem = arg.get_postBackElement(); var showProgress = !this._associatedUpdatePanelId; while (!showProgress && curElem) { if (curElem.id && this._associatedUpdatePanelId === curElem.id) { showProgress = true; } curElem = curElem.parentNode; } if (showProgress) { this._timerCookie = window.setTimeout(this._startDelegate, this._displayAfter); } }

Hai,

can u plz tell me any other sample.Me too facing same prblm...


Does this help?

http://weblogs.asp.net/rajbk/archive/2007/01/08/using-the-updateprogress-control-as-a-modal-overlay.aspx


Thanks for the suggestion Steve. In case anybody else is interested in doing something similar, here's the code for a simple extension of the UpdatePanel class that implements Steve's approach to the problem I originally described:

using System;using System.Collections.Generic;using System.Text;using System.Web;using System.Web.UI;namespace CustomAjaxControls{public class MyUpdatePanel : UpdatePanel{public MyUpdatePanel():base(){this.Load +=new EventHandler(MyUpdatePanel_Load);}private void MyUpdatePanel_Load(object sender, EventArgs e){RegisterClientScripts();}private void RegisterClientScripts(){StringBuilder library =new StringBuilder("");// start-up script (registered once for each instance of MyUpdatePanel on the page)this.Page.ClientScript.RegisterStartupScript(typeof(MyUpdatePanel),"StartUp" +this.UniqueID,"new MyUpdatePanel('" +this.ClientID +"');",true);// function library (registered once for all instances of MyUpdatePanel)library.AppendLine("// MyUpdatePanel javascript class");library.AppendLine("function MyUpdatePanel(panelId)");library.AppendLine("{");library.AppendLine("// properties");library.AppendLine("var _panel = document.getElementById(panelId);");library.AppendLine();library.AppendLine("// methods");library.AppendLine("this._handleBeginRequest = MyUpdatePanel_handleBeginRequest;");library.AppendLine();library.AppendLine("// hook into system events");library.AppendLine("Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(this._handleBeginRequest);");library.AppendLine();library.AppendLine("// MyUpdatePanel methods");library.AppendLine("function MyUpdatePanel_handleBeginRequest(sender, args)");library.AppendLine("{");library.AppendLine("var elem = args.get_postBackElement();");library.AppendLine();library.AppendLine("// find out if the object that requested the callback is our MyUpdatePanel");library.AppendLine("while (elem)");library.AppendLine("{");library.AppendLine("if (elem == _panel)");library.AppendLine("{");library.AppendLine("// hide the contents of the MyUpdatePanel until the asynchronrous callback returns");library.AppendLine("_panel.innerHTML ='Updating...';");library.AppendLine("return;");library.AppendLine("}");library.AppendLine("elem = elem.parentNode;");library.AppendLine("}");library.AppendLine("}");library.AppendLine("}// end class MyUpdatePanel");library.AppendLine();this.Page.ClientScript.RegisterClientScriptBlock(typeof(MyUpdatePanel),"library", library.ToString(),true);}}}

Disable an AnimationExtender

Hello,

I am developing a C# asp.net application and using the AJAX control toolkit.
I am using the AnimationExtender in order to add a fade effect to my page.
The AnimationExtender is a part of a gridView, since I wanted every row in the gridView to fade seperately.

Here is the gridView's code:
<asp:GridView ID="gvDocuments" runat="server" BorderWidth="0" ShowHeader="false" AutoGenerateColumns="False" Width="90%">
<Columns>
<asp:TemplateField HeaderText="Ticker">
<ItemTemplate>
<asp:Panel ID="pnlDoc" runat="server"><%# DataBinder.Eval(Container, "DataItem.docStart") % ></asp:Panel>
<asp:Panel ID="pnlQuote" runat="server"><%# DataBinder.Eval(Container, "DataItem.quote") %></asp:Panel>
<AjaxToolkit:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="pnlQuote">
<Animations>
<OnLoad>
<Sequence>
<FadeIn Fps="20" Duration="0.5" MinimumOpacity=".1" MaximumOpacity="1"/>
</Sequence>
</OnLoad>
</Animations>
</AjaxToolkit:AnimationExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView
The Grid is placed within an updatePanel with a timer.
What I would like to do is disable the AnimationExtender on some cases.

I tried using RowDataBound event:
((AjaxControlToolkit.AnimationExtender)e.Row.FindControl("AnimationExtender1")).Enabled = false;

And got an exception.

Is there a way to do that?

Thank you

Hello,

I do not see the handler defined for RowDataBound on your grid view. Could you provide us with your gridview with this defined and the code behind for RowDataBound and the exception?

Also, did you try to override page render and get teh control inside the grid's row?

Regards,

Louis


Sorry, my mistake.

I forgot to add:

if (e.Row.RowType ==DataControlRowType.DataRow)

So, it failed when going over the header first.

Thank you for trying to help...

Disable a button using AJAX

I saw this being discussed a couple of time but I wasn't able to figure out a solution. I got a webservice which is fired async by a button on my webform, now I need to disable the button to pretend ppl clicking multiple times on it. I tried it with that Javascript (added it to my .aspx in designer mode):

<scripttype="text/javascript">var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_initializeRequest(InitializeRequest);

prm.add_endRequest(EndRequest);

var postBackElement;

//fired when the update starts

function InitializeRequest(sender, args) {

postBackElement = args.get_postBackElement();

$get('<%= Button1.ClientID %>').enabled =false;

}

//fired when the update ends

function EndRequest(sender, args) {

$get('<%= Button1.ClientID %>').enabled =true;

}

</script>

However, my browser is throwing the error:

Error: prm has no properties
Source File:http://localhost:3889/solution/site.aspx
Line: 48

Anyone knows how to do it properly? Thanks a lot!

My guess is that your above code is firing too early and so when you call the getInstance() you're getting a null value. Try wrapping the var prm= and the prm.add_ calls inside function pageLoad() so that it fires after everything's been initialized.


The Page requestManager does not intercept the WebService Calls. Try Something like this.

For Example if have a button.

<input id="btnFire" type="button" value="ClickMe" onclick="FireWs" /
and JS:

function fireJs()
{

$get('btnFire').disabled = true:

//Now Call Your WS
WS.YourMethod(function()
{
//In the success handler enable your button
$get('btnFire').disabled = false:
}
);
}


To keep pages cleaner, I am also a fan of emitting JavaScript from the codebehind. Just add an attribute to a control like this:

dim controlUniqueID as string = ctype(me.findcontrol("myDisabledControl"), myDisabledControlType).uniqueID ' lets the JavaScript find any control on the page

submitButton.attribute.add("OnClick", "add a reference to a javascript function, or put inline code here.")

----

For more complex functions, I will register a javaScript function library and then reference methods in it.

cheers

Directory Services problem

I am trying to switch one of our sites to Beta 2 from the last pre-Beta version. Our site uses windows authentication and directory services to handle much of the security on the website. With the pre-Beta version it would either log you in. With the Beta 2, it doesn't give authentication errors, but doesn't know which user is there and only gives access that any basic user would have. Does anyone have any ideas how to fix this?We are using Request.ServerVariables.Get("AUTH_USER") to get the logged in user.
Has anyone got that to work with the beta 2?