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

[Solved] Reach javascript var content on server side with radAjaxManager.FocusControl()

4 Answers 99 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
alsi
Top achievements
Rank 1
alsi asked on 03 Jun 2008, 07:28 AM
Dear Developers!

I would like to know (is it possible?):

client side:
<script>
var actElement='ctl00_MainBody_txtName';
</script>

server side:
radAjaxManager.FocusControl(here reach - write- js var content) so look like this

radAjaxManager.FocusControl("ctl00_MainBody_txtName");

is it possible to reach js var on server side somehow?

thanks

4 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 03 Jun 2008, 08:01 AM
Hi alsi,

Using a hardcoded ID is not a good idea. A better approach would be to get reference to the ClientID of the control on the server and set focus to it.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
alsi
Top achievements
Rank 1
answered on 03 Jun 2008, 08:18 AM
Hi!

I don't use hard coded id-s. the thing what I exactly want:

I have two (or more) textboxes:

txtName
txtAddress

they have TextChanged event hadlers.
on aspx page I would like to do the following:
<asp:TextBox runat="server" ID="txtAddress" onfocus="actElement='<%# ClientID %>'" AutoPostBack="true" OnTextChanged="txtAddress_TextChange"  />

and after ajax Postback, I loose the focus, so I need to know the clicked textbox before postback.
imagine I have 20 textboxes and client don't want to fill in a determined order.

how can I do this?
thanks
0
Steve
Telerik team
answered on 03 Jun 2008, 10:57 AM
Hello alsi,

This help article should point you to the right direction. Give it a spin and let us know if further help is needed.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
alsi
Top achievements
Rank 1
answered on 04 Jun 2008, 06:42 AM
The following solution helped:

1. Create js focus setter function:
 <script language="javascript" type="text/javascript">
   var actElement;
  
   function focusActElement()
   {
        if(actElement != '')
            document.getElementById(actElement).focus();
   }
    </script>

2. To textboxes add onclick client side event with ClientID in the following way:
<asp:TextBox runat="server" ID="txtState" onclick="actElement='need ClientID here'" /> - You need to do on the server side:
txtState.Attributes.Add("click", "onfocus=actElement='" + txtState.ClientID + "'");

3. On Page_Load (Page.IsPostback) event call use RadAjaxManager:
radAjaxManager.ClientEvents.OnResponseEnd = "focusActElement";
and this use actElement var to set the focus.

this works for me.
Tags
Ajax
Asked by
alsi
Top achievements
Rank 1
Answers by
Steve
Telerik team
alsi
Top achievements
Rank 1
Share this question
or