This is a migrated thread and some comments may be shown as answers.

RadAjaxManager OnResponseEnd IE7 focus() not working

1 Answer 74 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
alsi
Top achievements
Rank 1
alsi asked on 02 Jun 2008, 07:14 AM
Hi All!

my problem is the following:
I have many textboxes. They have TextChanged events attached. After ajax postback I use the following code snippets to give the focus of the actual (clicked) textbox

my code :
js:
 function focusActElement()
   {
        if(actElement != '')
        {
            document.getElementById(actElement).focus();
             //if I use document.getElementById(actElement).select();
             //works fine in IE7, too but I don't want to select the texts in the boxes
        }
   }

in Page_Load i'm calling:
public static void TrackFocusAfterAjaxPostbacks(Page page, RadAjaxManager radAjaxManager)
    {
        // Insert startup script
        string scriptKey = "focusFunction";

        if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), scriptKey))
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), scriptKey, String.Format("focusActElement();"), true);
        }

        radAjaxManager.ClientEvents.OnResponseEnd = "focusActElement";
    }

In FF works fine, but in IE7 just with id.select() functioning well and I don't like to select texts in the textboxes.

can somebody help?
thx

1 Answer, 1 is accepted

Sort by
0
Accepted
The Oracle
Top achievements
Rank 1
answered on 01 Jul 2008, 07:13 PM
Hey alsi,

I found this script that might work for you:

function clearSelection () {  
    if (document.selection)  
        document.selection.empty();  
    else if (window.getSelection)  
        window.getSelection().removeAllRanges();  

You can call it after you do your input.select().

Here is the html of a simple form for you to test it (I modified it from the url provided above):

<html> 
<head> 
<title>blur.html</title> 
<script type="text/javascript">  
function onloader() {  
document.MyForm.MyInput.focus();  
document.MyForm.MyInput.select();  
}  
function clearSelection () {  
if (document.selection)  
document.selection.empty();  
else if (window.getSelection)  
window.getSelection().removeAllRanges();  
}  
</script> 
</head> 
<body > 
<form action="" method="get" name="MyForm">  
<input type="text" name="MyInput" 
value="Hello World" > 
 
<button onclick="onloader();">Set</button> 
<button onclick="clearSelection();">Clear</button> 
</form> 
</body> 
</html> 


Graeme
Tags
Ajax
Asked by
alsi
Top achievements
Rank 1
Answers by
The Oracle
Top achievements
Rank 1
Share this question
or