Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Focus with ASP.NET AJAX Control Toolkit

Tags:

asp.net

I'm using the AutoComplete control from the ASP.NET AJAX Control Toolkit and I'm experiencing an issue where the AutoComplete does not populate when I set the focus to the assigned textbox.

I've tried setting the focus in the Page_Load, Page_PreRender, and Page_Init events and the focus is set properly but the AutoComplete does not work. If I don't set the focus, everything works fine but I'd like to set it so the users don't have that extra click.

Is there a special place I need to set the focus or something else I need to do to make this work? Thanks.

like image 452
Jonathan S. Avatar asked Oct 15 '22 19:10

Jonathan S.


2 Answers

We had exactly the same problem. What we had to do is write a script at the bottom of the page that quickly blurs then refocuses to the textbox. You can have a look at the (terribly hacky) solution here: http://www.drive.com.au

The textbox id is MainSearchBox_SearchTextBox. Have a look at about line 586 & you can see where I'm wiring up all the events (I'm actually using prototype for this bit.

Basically on the focus event of the textbox I set a global var called textBoxHasFocus to true and on the blur event I set it to false. The on the load event of the page I call this script:

if (textBoxHasFocus) {
    $get("MainSearchBox_SearchTextBox").blur();
    $get("MainSearchBox_SearchTextBox").focus();
}  

This resets the textbox. It's really dodgy, but it's the only solution I could find

like image 138
Glenn Slaven Avatar answered Nov 15 '22 04:11

Glenn Slaven


this is waste , its simple

this is what you need to do

controlId.focus(); in C# controlID.focus() in VB

place this in page load or button_click section

eg. panel1.focus(); if panel1 has model popup extender attached to it, then we put this code in page load section

like image 35
paritosh Avatar answered Nov 15 '22 05:11

paritosh