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

Updating label text without postback

5 Answers 244 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
steve
Top achievements
Rank 1
steve asked on 30 Oct 2008, 01:57 PM
Hi,

I've posted this in another forum on here by accident, I think I've put this into the correct forum now.

I want to know if it is possible to update a label that is wrapped in a RadAjaxPanel using code behind?  I.e.:

ASP.NET:

<

telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" height="200px" width="300px"> <asp:Label ID="Connections" runat="server" Text="0"></asp:Label> </telerik:RadAjaxPanel>

Code behind ( C# code ):

Connections.text = "100";

I can't get this to work unless I do a postback which is obviously not what I want.
I know this will probably work if I have a timer event and do it in that, but don't want to use one.

Any help is much appreciated.

Regards,
Steve

5 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 30 Oct 2008, 03:38 PM
Hi steve,

You could use the OnAjaxRequest event in order to update the asp Label. More information on this matter could be found here

Kind regards,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
steve
Top achievements
Rank 1
answered on 30 Oct 2008, 03:59 PM

Hi,

Thanks for reply and information.  I've quickly looked at the example it gives but still unsure as to how I'd implement this.       

I've used a timer for now to cause the event:

 

<

asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>Connections :<asp:Label ID="Connections" runat="server" Text="0"></asp:Label><br />
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick"></asp:Timer></ContentTemplate>
</asp:UpdatePanel>

What I really want is when a user connects to a socket I have listening for connections, is to update the Connections.text.  My timer code:

 

 

protected void Timer1_Tick(object sender, EventArgs e)
{
  
if (server != null)
  {
     t
his.Connections.Text = server.nClientConnections.ToString();
  }
}

I'd like this event to be called when a user connects, how can this be done with the OnAjaxRequest event? I guess I need to replace the UpdatePanel with RadAjaxPanel?

Regards,
Steve

 

0
steve
Top achievements
Rank 1
answered on 31 Oct 2008, 10:59 AM

Hi again,

I've now got this code:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" onajaxrequest="RadAjaxManager1_AjaxRequest"></telerik:RadAjaxManager><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

 

 

 

And in my C# :

 

 

protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
  
this.Label1.Text = "100";// server.nClientConnections.ToString();
}

I raise this event in my code when a user connect:

 

page.RadAjaxManager1.RaisePostBackEvent(

"server");

 

The event gets raised, but the Label1.text is not updated...
What am I doing wrong?

Regards,
Steve

 

 

 

0
Maria Ilieva
Telerik team
answered on 03 Nov 2008, 07:18 AM
Hello steve,
 
Please try the following code to initiate AjaxRequest on PageLoad:

           <script type="text/javascript"> 
                    window.onload = function() 
                    { 
                        setTimeout( function(){ 
                            <%= RadAjaxManager1.ClientID %>.AjaxRequest("InitialPageLoad"); 
                        }, 100); 
                    } 
                </script> 


Sincerely yours,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
steve
Top achievements
Rank 1
answered on 03 Nov 2008, 11:38 AM
Hi,

I can't get that javascript to work ( compile...)

I don't think it is possible to update a label without raising some kind of event, whether this be a timer event or a button click event.

All the examples I have seen with updating of labels etc, always have an onclick button event associated with them, obviously this is not what I want.

I guess I will just have to use a timer event :-(

Regards,
Steve

Tags
Ajax
Asked by
steve
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
steve
Top achievements
Rank 1
Share this question
or