Update window content before opening

2 posts, 0 answers
  1. Mickael
    Mickael avatar
    24 posts
    Member since:
    Oct 2014

    Posted 07 Oct 2014 Link to this post

    I am trying to open a window with a label set from code behind.
    The window opens but the label is not set

    <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">
        <script type="text/javascript" language="javascript">
            function aspButtonCallbackFn(sender, args) {
                PageMethods.PrepareForSearchResult(args.get_text(), MyMethod_Result);
            }
     
            function MyMethod_Result(pResult) {
                if (pResult == 2) {
                        var wnd = $find("<%=modalPopup.ClientID %>");
                        wnd.show();
                    }
        }
        </script>
    </telerik:RadCodeBlock>

    This is how the popup is declared:

    <telerik:RadWindow
        ID="modalPopup"
        runat="server"
        AutoSizeBehaviors="Width, Height"
        AutoSize="true"
        VisibleStatusbar="false"
        Behaviors="Move"
        VisibleOnPageLoad="false"
        ReloadOnShow="true"
        Modal="true"
        EnableShadow="true">
        <ContentTemplate>
            <asp:UpdatePanel ID="PdtPnl_ForAddExisting" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <div style="display: table; width: 100%">
                        <div style="display: table-row; vertical-align: middle">
                            <div style="display: table-cell; padding-top: 10px; padding-left: 10px; padding-bottom: 5px; padding-right: 10px;">
                                <asp:Label
                                    ID="Lbl_Pnl_ForAddExisting"
                                    runat="server"
                                    Text="" />
                            </div>
                        </div>
                    </div>
                    <div style="display: table; width: 100%">
                        <div style="display: table-row; vertical-align: middle">
                            <div style="display: table-cell; padding-top: 5px; padding-left: 10px; padding-bottom: 10px; padding-right: 5px;">
                                <asp:Button
                                    ID="Bttn_Add_ForAddExisting"
                                    Width="100"
                                    OnClick="Bttn_Add_ForAddExisting_Click"
                                    Text="Add"
                                    runat="server"
                                    class="button" />
                            </div>
                            <div style="display: table-cell; padding-top: 5px; padding-left: 5px; padding-bottom: 10px; padding-right: 10px;">
                                <asp:Button
                                    ID="Bttn_Cancel_ForAddExisting"
                                    Width="100"
                                    OnClick="Bttn_Cancel_ForAddExisting_Click"
                                    Text="Cancel"
                                    runat="server"
                                    class="button" />
                            </div>
                        </div>
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
        </ContentTemplate>
    </telerik:RadWindow>

    And this is the WebMethod

    [WebMethod]
    public static int PrepareForSearchResult(string pText)
    {
        if (String.IsNullOrEmpty(pText) == true)
        {
            return -1;
        }
        _instance.Lbl_Pnl_ForAddExisting.Text = String.Format("Do you want to add '{0}'?", pText);
        _instance.PdtPnl_ForAddExisting.Update();
        return 2;
    }

    Not sure what I am doing wrong.
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 08 Oct 2014 Link to this post

    Hi Michael,

    Page methods should be considered as an easy to use webservice. They return JSON and not an HTML response for the page. They are static members of the page class, so they cannot use control instances from the page (i.e., concrete controls). You can read more about it here: http://blogs.telerik.com/aspnet-ajax/posts/13-03-21/different-ways-to-make-a-request-to-the-server.

    If you can manage to get this working without the RadWindow, the same approach should work with the RadWIndow as well.

    What I would suggest is returning the needed data from the page method and using JavaScript to set it to the span where you want it.


    Regards,

    Marin Bratanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top