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

Firing clientside script using Label.Text does not work

4 Answers 79 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
the_developer_cali
Top achievements
Rank 1
the_developer_cali asked on 14 Feb 2009, 09:08 PM

This is very common in the old Radcontrols for ASP.NET...

1. In the master page

<form id="form1" runat="server" style="height:100%">  
        <telerik:RadScriptManager ID="MasterRadScriptManager" runat="server" EnableScriptCombine="true"></telerik:RadScriptManager>    
<telerik:RadAjaxManager ID="MasterRadAjaxManager" runat="server" OnAjaxRequest ="MasterRadAjaxManager_AjaxRequest" EnablePageHeadUpdate="False">  
            <AjaxSettings/> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
</form> 

2. From the Code Behind Expose the RadAjaxManager 
        public RadAjaxManager RadAjaxManager  
        {  
            get  
            {  
                return this.MasterRadAjaxManager;  
            }  
        }  
 
3. From the content Page aspx
<asp:Content ID="CLP" ContentPlaceHolderID="MCPH" runat="server">  
          <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_OnClick" /> 
<asp:Label ID="lblClientScript" runat="server" Text=""></asp:Label> 
</asp:Content> 
4. From content Page code behind wireup btnsave and lblclientscript on pageload
protected void Page_Load(object sender, EventArgs e)  
{  
     this.Master.RadAjaxManager.AjaxSettings.AddAjaxSetting(btnSave, lblClientScript);  
     this.Master.RadAjaxManager.AjaxSettings.AddAjaxSetting(this.Master.RadAjaxManager, lblClientScript);  
}  
 
protected void btnSave_OnClick(object sender, EventArgs e)  
{  
    lblClientScript.Text = "alert('test "+ DateTime.Now.ToLongTimeString() +"');";  

The alert only works on the First Click but subsequent click does not fire the alert.
But if I just set the Label to some text I can see that it is refreshing the Label...again this use to work in the Old RadAjax
protected void btnSave_OnClick(object sender, EventArgs e)     
{     
    lblClientScript.Text = "updating "+ DateTime.Now.ToLongTimeString();     

I also know...that i can just use ...this.Master.RadAjaxManager.ResponseScripts.Add("alert('test')"),
which works but for some instance I have to use Labels...

 

4 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 16 Feb 2009, 04:06 PM
Hi,

I would suggest your to use the GetCurrent() static method of RadAjaxManager to access the main manager in any content page instead of the preceding property as described here
Regarding the specific issue you are facing, please try adding the ajax settings on Page.PreRender event in the content page as below:

protected void Page_PreRender(object sender, EventArgs e)        
{        
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);     
    manager .AjaxSettings.AddAjaxSetting(btnSave, lblClientScript);        
    manager .AjaxSettings.AddAjaxSetting(manager, lblClientScript);        
}    

Let me know if it makes any difference.

Kind regards,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Yuriy Rogach
Top achievements
Rank 1
Iron
answered on 27 Feb 2009, 08:58 AM
Hi Iana,
 
I have the same problem as topics author and your suggestion doesn't help. Any other idea how to add javascript function after RadAjaxRequest  ?
0
Iana Tsolova
Telerik team
answered on 27 Feb 2009, 02:55 PM
Hi Yuriy,

Please review this help topic on how to execute custom javascript after ajax request. Give a try and let me know if you need further directions/help.

Best wishes,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Yuriy Rogach
Top achievements
Rank 1
Iron
answered on 27 Feb 2009, 03:10 PM
Hi Iana,

The problem is not how to execute custom javascript, but how to add custom javascript function to the page after AJAX request.

Anyway this method helps

ScriptManager.RegisterStartupScript(

this.Page, this.Page.GetType(), "key", script, true);

I registered script from user control, so using this.Page is important!

 

 

Tags
Ajax
Asked by
the_developer_cali
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Yuriy Rogach
Top achievements
Rank 1
Iron
Share this question
or