1. Ingo Dignas
    Ingo Dignas avatar
    16 posts
    Member since:
    May 2009

    Posted 24 Jun 2009 Link to this post

    I like to get a radalert directly on Button Click. The code below works, but the radalert comes not directly up. Is there a way to force the execution of the responsescript directly?

    I've following code in a button_onClick Event:

     

    private

     

    void btbuy_clicked(object sender, EventArgs e)

     

    {

     

    ......
    ......

    foreach

     

    (Article art in articlesselected)

     

    {

     

    if (ct + 1 > art.MaxAnz)

     

    {

    RadAjaxManager1.ResponseScripts.Add(

    "(function(){var f = function(){radalert('<h4>Dieser Artikel ist leider nicht mehr verfgbar!</h4>', 330, 210);Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()");

     

     

    return;

     

    }

    myOrder.setArticle(1, art);

    }

     

     

    ...
    ...

    }

    This is the aspx file:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ProtelShop._Default" MasterPageFile="~/ProtelShop.Master" %> 
     
    <%@ Register assembly="Telerik.OpenAccess, Version=2009.1.405.1, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342" namespace="Telerik.OpenAccess" tagprefix="telerik" %> 
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik"  %> 
     
     
     
    <%@ Reference Control="~/Controls/ShopBuyTooltip.ascx" %> 
     
     
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">  
    <telerik:RadAjaxManager runat="server">  
     <AjaxSettings>    
            <telerik:AjaxSetting AjaxControlID="Button1">    
                <UpdatedControls>    
                    <telerik:AjaxUpdatedControl ControlID="RadWindowManager1" />    
                </UpdatedControls>    
            </telerik:AjaxSetting>    
        </AjaxSettings>    
     
        </telerik:RadAjaxManager> 
        <div> 
          
        </div> 
        <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">  
          
        </telerik:RadScriptManager> 
        <telerik:RadWindowManager runat="server">  
        </telerik:RadWindowManager> 
        <script type="text/javascript">  
            //<![CDATA[
                function hideActiveToolTip()
                {            
                    var controller = Telerik.Web.UI.RadToolTipController.getInstance();
                    var tooltip = controller.get_activeToolTip();
                    if (tooltip)
                    {
                        tooltip.hide();
                    }
                }
                
                Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);
                function beginRequestHandler(sender, args)
                {
                    var prm = Sys.WebForms.PageRequestManager.getInstance();
                    if (args.get_postBackElement().id.indexOf('RadScheduler1') != -1)
                    {
                        hideActiveToolTip();
                    }
                }
                
                function clientBeforeShow (sender, eventArgs) {
                 w = $telerik.$(window).width() / 2;
                 h = $telerik.$(window).height() / 2;
                   
                 if ((sender._mouseX > w) && (sender._mouseY > h)) {
                 sender.set_position(Telerik.Web.UI.ToolTipPosition.TopLeft);
                 return;
                 }
                 if ((sender._mouseX < w) && (sender._mouseY > h)) {
                 sender.set_position(Telerik.Web.UI.ToolTipPosition.TopRight);
                 return;
                 }
                 if ((sender._mouseX > w) && (sender._mouseY < h)) {
                 sender.set_position(Telerik.Web.UI.ToolTipPosition.BottomLeft);
                 return;
                 }
             sender.set_position(Telerik.Web.UI.ToolTipPosition.BottomRight);
                }
            //]]> 
            </script> 
        <telerik:OpenAccessDataSource ID="OpenAccessDataSource1" runat="server"   
            ObjectContextProvider="ProtelShop.ObjectScopeProvider1, ProtelShop"   
            TypeName="ProtelAccess.Article" ContextTypeName="" OrderBy=""   
            Where="MaxAnz &gt; 0" > 
        </telerik:OpenAccessDataSource> 
          <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                 </AjaxSettings> 
         </telerik:RadAjaxManager> 
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server">          
            </telerik:RadSkinManager> 
            <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server"  DecoratedControls="All"/>  
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" > 
         <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">  
                <ContentTemplate>                  
                      <asp:Panel ID="Panel2" runat="server" CssClass="title" > 
                       Seminar Angebote  
                   </asp:Panel> 
        <telerik:RadScheduler ID="RadScheduler1" runat="server" DataEndField="EndTime"   
            DataKeyField="ArtNr" DataSourceID="OpenAccessDataSource1"   
            DataStartField="StartTime" DataSubjectField="Name" HoursPanelTimeFormat="htt"   
            ValidationGroup="RadScheduler1"  ReadOnly="true"  SelectedView="MonthView">  
        </telerik:RadScheduler> 
        <telerik:RadToolTipManager runat="server" ID="RadToolTipManager1" Width="320" Height="170" 
                        Animation="None" HideEvent="LeaveToolTip" Text="Loading..." 
                        OnAjaxUpdate="RadToolTipManager1_AjaxUpdate" OnClientBeforeShow="clientBeforeShow" /> 
                          
                          
                       <br /> 
             
             </ContentTemplate> 
            </asp:UpdatePanel> 
             <asp:UpdatePanel runat="server" ID="UpdatePanel2" UpdateMode="Conditional">  
               <ContentTemplate> 
               <br /> 
                   <asp:Panel ID="Panel1" runat="server" CssClass="title">  
                       Warenkorb  
                   </asp:Panel> 
               <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="true"   
                        AllowAutomaticUpdates="true" AutoGenerateColumns="true"   
                        AutoGenerateDeleteColumn="true" OnDeleteCommand="RadGrid1_DeleteCommand"  OnItemDataBound="RadGrid1_ItemDataBound" > 
                        <MasterTableView AutoGenerateColumns="False" RetrieveAllDataFields="false" ShowFooter="true">  
                            <Columns> 
                                <telerik:GridBoundColumn DataField="ArtNr" HeaderText="Artikelnummer">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="Name" HeaderText="Artikelname">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="ArtName" HeaderText="Artikelbeschreibung">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="StartTime" HeaderText="Start">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="EndTime" HeaderText="Ende">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="Quantity" HeaderText="Anzahl">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="ArtPrice" HeaderText="Preis">  
                                </telerik:GridBoundColumn> 
                                 
     
                            </Columns> 
                              
                        </MasterTableView> 
                    </telerik:RadGrid> 
                 
               </ContentTemplate> 
             </asp:UpdatePanel> 
            </telerik:RadAjaxPanel> 
            <br /> 
             <asp:UpdatePanel runat="server" ID="UpdatePanel3" UpdateMode="Conditional">  
               <ContentTemplate> 
            <div style="text-align:right">  
        <asp:Button ID="Button1" runat="server" Text="Zur Kasse" onclick="Button1_Click" Width="100px"  /> 
        </div> 
        <asp:Literal ID="LiteralScript" runat="server"></asp:Literal> 
        </ContentTemplate> 
        </asp:UpdatePanel> 
          
     </asp:Content> 
  2. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 26 Jun 2009 Link to this post

    Hello Joerg,

    I believe that the following blog post will be of help: Executing JavaScript function from server-side code. I suggest to first make sure that a simple alert is executed (e.g. replace radalert with alert()) and when your logic work correctly, use the radalert method again (making sure of course that the RadWindowManager is already rendered on the page).

    In your code however, I noticed that you are using both RadAjax and ASP.NET AJAX's update panels. I strongly recommend to use only one of the type - either RadAjaxManager/RadAjaxPanel or UpdatePanel controls.



    All the best,
    Georgi Tunev
    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.
  3. Ingo Dignas
    Ingo Dignas avatar
    16 posts
    Member since:
    May 2009

    Posted 26 Jun 2009 Link to this post

    Hello Georgi,

    thank's a lot....I'm not sure but I think I've tried the following solution before:
    string scriptstring = "radalert('<h4>Dieser Artikel ist leider nicht mehr verfügbar!</h4>', 330, 210);";    
     
    ScriptManager.RegisterStartupScript(this, this.GetType(), "radalert", scriptstring, true);   

    May it be, that it didn't work because of the update panels?
  4. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 26 Jun 2009 Link to this post

    Hi Joerg,

    Yes, this is one possible reason. I assume that you now can successfully call the radalert dialog, am I right? If you still experience problems it will be best to open a support ticket and send me a sample application that I could run locally and that reproduces your exact setup and logic. This will help me provide you with the most appropriate solution.


    Sincerely yours,
    Georgi Tunev
    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.
  5. Ingo Dignas
    Ingo Dignas avatar
    16 posts
    Member since:
    May 2009

    Posted 26 Jun 2009 Link to this post

    Hi Georgi,

    it work now....but I've a question regarding radajaxpanel and the ajaxmanager. I've used the telerik example RadScheduler with tooltip. I've extended the tooltip with a button. The ClickEvent is implemenet in the main page (code behind - used a deligate in the tooltip control). The Button works fine, but after executing the onclick event I like to update my rategrid1. It works with an updatepanel if I use UpdatePanel2.Update(). But if i use radajaxpanel the rategrid1 doesn't get updated even on rategrid1.rebind(). Also the Button on the bottom of the page, which is enabled=false should be updated. I guess I've to use the ajax manager, but I'm not sure how this works. Maybe you can tell me how to manage the updates.

    Here is my new code again:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ProtelShop._Default" MasterPageFile="~/ProtelShop.Master" %> 
     
    <%@ Register assembly="Telerik.OpenAccess, Version=2009.1.405.1, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342" namespace="Telerik.OpenAccess" tagprefix="telerik" %> 
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik"  %> 
     
     
     
    <%@ Reference Control="~/Controls/ShopBuyTooltip.ascx" %> 
     
     
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">  
     
      <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
     <AjaxSettings>    
            <telerik:AjaxSetting AjaxControlID="RadGrid1">    
                <UpdatedControls>    
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"  />    
                </UpdatedControls>    
            </telerik:AjaxSetting>    
            <telerik:AjaxSetting AjaxControlID="RadWindowManager1">    
                <UpdatedControls>    
                    <telerik:AjaxUpdatedControl ControlID="RadWindowManager1"  />    
                </UpdatedControls>    
            </telerik:AjaxSetting>    
     
        </AjaxSettings>   
        </telerik:RadAjaxManager> 
     
        <div> 
          
        </div> 
        <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">  
          
        </telerik:RadScriptManager> 
           
        <telerik:RadWindowManager runat="server" ID="RadWindowManager1">  
        </telerik:RadWindowManager> 
        <script type="text/javascript">  
     
            //<![CDATA[
           
                function hideActiveToolTip()
                {            
                    var controller = Telerik.Web.UI.RadToolTipController.getInstance();
                    var tooltip = controller.get_activeToolTip();
                    if (tooltip)
                    {
                        tooltip.hide();
                    }
                }
                
                Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);
                function beginRequestHandler(sender, args)
                {
                    var prm = Sys.WebForms.PageRequestManager.getInstance();
                    if (args.get_postBackElement().id.indexOf('RadScheduler1') != -1)
                    {
                        hideActiveToolTip();
                    }
                }
                
                function clientBeforeShow (sender, eventArgs) {
                 w = $telerik.$(window).width() / 2;
                 h = $telerik.$(window).height() / 2;
                   
                 if ((sender._mouseX > w) && (sender._mouseY > h)) {
                 sender.set_position(Telerik.Web.UI.ToolTipPosition.TopLeft);
                 return;
                 }
                 if ((sender._mouseX < w) && (sender._mouseY > h)) {
                 sender.set_position(Telerik.Web.UI.ToolTipPosition.TopRight);
                 return;
                 }
                 if ((sender._mouseX > w) && (sender._mouseY < h)) {
                 sender.set_position(Telerik.Web.UI.ToolTipPosition.BottomLeft);
                 return;
                 }
             sender.set_position(Telerik.Web.UI.ToolTipPosition.BottomRight);
                }
            //]]> 
            </script> 
        <telerik:OpenAccessDataSource ID="OpenAccessDataSource1" runat="server"   
            ObjectContextProvider="ProtelShop.ObjectScopeProvider1, ProtelShop"   
            TypeName="ProtelAccess.Article" ContextTypeName="" OrderBy=""   
            Where="MaxAnz &gt; 0" > 
        </telerik:OpenAccessDataSource> 
           
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server">          
            </telerik:RadSkinManager> 
            <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server"  DecoratedControls="All"/>  
         
                        
                      <asp:Panel ID="Panel2" runat="server" CssClass="title" > 
                       Seminar Angebote  
                   </asp:Panel> 
                 
                   <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" > 
        <telerik:RadScheduler ID="RadScheduler1" runat="server" DataEndField="EndTime"   
            DataKeyField="ArtNr" DataSourceID="OpenAccessDataSource1"   
            DataStartField="StartTime" DataSubjectField="Name" HoursPanelTimeFormat="htt"   
            ValidationGroup="RadScheduler1"  ReadOnly="true"  SelectedView="MonthView" Height="350">  
        </telerik:RadScheduler> 
        <telerik:RadToolTipManager runat="server" ID="RadToolTipManager1" Width="320" Height="170" 
                        Animation="None" HideEvent="LeaveToolTip" Text="Loading..." 
                        OnAjaxUpdate="RadToolTipManager1_AjaxUpdate" OnClientBeforeShow="clientBeforeShow" /> 
                          
                        </telerik:RadAjaxPanel> 
                       <br /> 
             
     
     
          
                <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server" > 
          
               <br /> 
                   <asp:Panel ID="Panel1" runat="server" CssClass="title">  
                       Warenkorb  
                   </asp:Panel> 
               <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="true"   
                        AllowAutomaticUpdates="true" AutoGenerateColumns="true"   
                        AutoGenerateDeleteColumn="true" OnDeleteCommand="RadGrid1_DeleteCommand"  OnItemDataBound="RadGrid1_ItemDataBound" > 
                        <MasterTableView AutoGenerateColumns="False" RetrieveAllDataFields="false" ShowFooter="true">  
                            <Columns> 
                                <telerik:GridBoundColumn DataField="ArtNr" HeaderText="Artikelnummer">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="Name" HeaderText="Artikelname">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="ArtName" HeaderText="Artikelbeschreibung">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="StartTime" HeaderText="Start">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="EndTime" HeaderText="Ende">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="Quantity" HeaderText="Anzahl">  
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="ArtPrice" HeaderText="Preis" DataFormatString="{0:C}">  
                                </telerik:GridBoundColumn> 
                                 
     
                            </Columns> 
                              
                        </MasterTableView> 
                    </telerik:RadGrid> 
         
            </telerik:RadAjaxPanel> 
            <br /> 
     
        <telerik:RadAjaxPanel ID="RadAjaxPanel3" runat="server" > 
        
            <div style="text-align:right">  
        <asp:Button ID="Button1" runat="server" Text="Zur Kasse" onclick="Button1_Click" Width="100px"  /> 
        </div> 
          </telerik:RadAjaxPanel> 
     
          
     </asp:Content> 


      private void btbuy_clicked(object sender, EventArgs e)  
            {  
                AppointmentToolTip mytooltip = (AppointmentToolTip)sender;  
                TempOrder myOrder = new TempOrder();  
                int ArtID = int.Parse(mytooltip.TargetAppointment.ID.ToString());  
                int ct = 0;  
                for (int a = 0; a < myOrders.Count; a++)  
                {  
                    TempOrder to = (TempOrder)myOrders[a];  
                    if (to.ArtNr == ArtID)  
                        ct++;  
     
                }  
     
                  
                var articlesselected = from a in cashedScope.Extent<Article>()  
                                       where a.ArtNr == ArtID  
                                       select a;  
     
                  
                cashedScope.Transaction.Begin();  
     
                foreach (Article art in articlesselected)  
                {  
                    if (ct + 1 > art.MaxAnz)  
                    {  
     
                        string scriptstring = "radalert('<h4>Dieser Artikel ist leider nicht mehr verfügbar!</h4>', 330, 210);";    
                        ScriptManager.RegisterStartupScript(thisthis.GetType(), "radalert", scriptstring, true);    
                        return;  
                    }  
                    myOrder.setArticle(1, art);  
                }  
     
                cashedScope.Transaction.Commit();  
                myOrders.Add(myOrder);  
                Session["myOrders"] = myOrders;  
                if (myOrders.Count > 0)  
                {  
                    Button1.Enabled = true;  
            
                }  
                TAmount += myOrder.ArtPrice;  
     
                RadGrid1.Rebind();  
                
            } 

    Thanks
  6. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 01 Jul 2009 Link to this post

    Hello Joerg,

    As far as I can see from your code you have a complex usage of AJAX in your demo. However, I am not sure why you have doubled ajaxified the grid - once with a RadAjaxPanel and once with the RadAjaxManager, and as far as I can see  the ajax setting concerning the RadWindowManager does nothing. However, I cannot be sure about all this until I examine your setup locally on my side.

    What I assume might be happening is the following:

    1. When you press the button in the tooltip, this updates the tooltip's content update panel and also the parent RadAjaxPanel with ID RadAjaxPanel1.
    2. Even if you rebind the grid in the button click event, the grid will be actually rebinded but the new data will not be send to the browser and rendered because the update panel which holds the grid is not updated and it keeps its old data.

    This being said, what I can suggest is the following:

    1. Use the approach which you have already found of a programmatic update of the update panel by calling Update().
    2. Put all the scheduler, grid and tooltip manager i the very same RadAjaxPanel and do not wrap them in different panels.

    In case you need further assistance, please prepare a sample, fully runnable reproduction demo (use Northwind or a fake programmatic datasource for the scheduler and the grid), open a new support ticket and send it to me along with very detailed reproduction steps and explanations and I will do my best to help. 

     


    Sincerely yours,

    Svetlina
    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.
Back to Top