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

Telerik Ajax Manager do not let me to access components...

3 Answers 66 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Yan Moura
Top achievements
Rank 1
Veteran
Iron
Yan Moura asked on 04 Feb 2010, 06:51 PM
Question quick version:
How do I change the visibility of an ASP control (eg. a button) from code behind without to add it in the Telerik Ajax Manager?


Question long version:
I am very frustrated. I am strugling with this problem for two days now, and couldnt achieve any success so far.

Some time ago, I have written a very stable chat service in VS 2008, and the client-side was done using traditional Ajax coding (JS).

Well, my boss is a technology freak and told me that I should get rid of my conventional code and use all these cool Telerik Ajax components. For the mostly tasks such as checking queue, enter queue, etc, it goes ok, but my real nightmare started in the main chat page.

Ok, let me try to explain what is going on.

I have the chat.aspx where there are all the traditional VS components (buttons, textfields, timers, etc) and also the Telerik Ajax Manager and the Rad Script Manager. Running behind it, I have my chat.aspx.cs code (c-sharp).

In the chat.aspx I have four main components:

txtChat -> big textfield where all messages show up
txtMessage -> small textfield where user type in his message
btnSend -> button to be clicked and send typed message
tmrUpdateChat -> a timer that bangs server each 2 seconds to update txtChat

In the Telerik Ajax Manager, I configured it this way:

who initiate Ajax request: tmrUpdateChat
who is updated: txtChat

Fine, it is working nicely!

The case is that when the chat operator (in the other side) ends the conversation, a message is shown in the client txtChat warning that the chat session was closed. In addition, the send button (btnSend) and the typing textfield (txtMessage) should be turned invisible with:

txtMessage.Visible = false;
btnSend.Visible = 
false;

For any unknown reason, the above commands are being ignored and nothing happens (my components just keep there, visible).

I figured out that if I change my Ajax Manager settings this way:

who initiate Ajax request: tmrUpdateChat
who is updated: txtChat, btnSend, txtMessage

Then the CS commands DO work and make my components invisible. The sad part of the story is that in this case, a new problem appear - every time the timer updates the chat, the txtMessage textfield lose focus, what is very annoying for whose is trying to type a message.

I dont know if I could make myself clear, as this issue is a bit hard to explain. It is driving me crazy.

What makes me more frustrated is that I had everything working fine with traditional JS, and using this technology supposed to be better, but the fact is that I am feeling as I would just spending a lot of time for nothing.

:(

Any help apreciated.

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 10 Feb 2010, 06:55 AM
Hello Yan Moura,

To set the focus to a specific control after AJAX callback has been performed, you can use the FocusControl() method of the RadAjaxManager control. The following online example demonstrates this approach:

Focus control

I hope this helps,
Martin
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Yan Moura
Top achievements
Rank 1
Veteran
Iron
answered on 10 Feb 2010, 06:01 PM
Martin,

Thanks for trying to help, but unfortunatelly it doesnt work. The solution is not as simple as force focus to the textfield.
I could do that using the Focus() CS method right after the timer ticks, this way:

txtMessage.Focus(); 

However, it is not that simple. I have other components in the chat page also, such as a collection of dropdown listboxes, where the user can select a product whose he is asking for support. This way, if I force the focus back to the txtMessage component after the timer tick, it will cause a problem with the dropdowns: suppose that the user is not typing in the right time when the timer ticks, but scrolling the dropdown box in the search for a product - the forced focus will close the dropdown list.

To solve that, I needed that I could do one of the following things:

1) That the Telerik Manager could update the txtChat (main window) without to take the focus out of the txtMessage. Before you say that it cannot be done, I say that it can. When my application was pure Javascript, I used the JS timeout method to trig the updates, and the txtChat was updated regardless the fact of user being typing or using the dropdown lists. Of course I wasnt using VS components. Instead, my chat area (where the conversation is shown) was a div tag that I accessed directly through its id property. Maybe this is the difference?

Anyway, if the above is not possible by using a VS component plus Telerik, the following situation would solve my problem too:

2) If I could detect what component have the current focus, this way I could set focus to the right component. I have googled after a way to do that, and I have found that I could detect it through the Enter and Leave events, but I couldnt find the availability of these events on CS for code behind.

Any idea?
0
robertw102
Top achievements
Rank 1
answered on 10 Feb 2010, 10:08 PM
I'm thinking the best way to solve your issue would be to add the RadAjaxManager as an Ajax trigger and it will update the txtChat and btnSend controls. So when your timer ticks, it will check if the support operator is offline and then send back a script that will make the RadAjaxManager raise an ajax request to hide the txtChat and btnSend buttons.

So in you Timer_Tick event you would write this:

if (operator_offline)
{
RadAjaxManager1.ResponseScripts.Add(RadAjaxManager1.GetAjaxEventReference("HideChatControls");
}

This will return a script that will then raise the ajax request for the RadAjaxManager control if the operator is offline.

Then you handle the RadAjaxManager AjaxRequest event and in that event hide the txtChat and btnSend like so:

if (e.Argument == "HideChatControls")
{
txtChat.Visible = false;
btnSend.Visible = false;
}

This checks that you want to hide the chat controls and then sets hides them.

So pretty much you create a new AjaxSetting for the RadAjaxManager and its UpdatedControls would be txtChat and btnSend. This way you don't need to add txtChat and btnSend to to timer's ajax setting and it won't disable the controls unless the support operator is offline.

I hope that solves your problem.

Tags
Ajax
Asked by
Yan Moura
Top achievements
Rank 1
Veteran
Iron
Answers by
Martin
Telerik team
Yan Moura
Top achievements
Rank 1
Veteran
Iron
robertw102
Top achievements
Rank 1
Share this question
or