Preview RadTextBox within RadGrid using RadWindow

6 posts, 1 answers
  1. Alex
    Alex avatar
    31 posts
    Member since:
    Jun 2009

    Posted 16 Nov 2010 Link to this post

    Hi,
         I have a RadGrid that serves to show text for preview and editing. I have a detail aspx page which serves as the parent, and then user control pages within a radtabstrip with a multipageview. When I try to preview the text box within the grid (which is wihtin the usercontrol), I get a null each time I reference the window manager, the window comes back null. I have a piece of it working where I preview images, for some reason it reads tha manager fine. As you can see from the code below, I've tried a few things. Let me know if there's a viable solution to my problem. Again, informationWindowLocation works, and the OnClientPageLoad doesn't.
    protected void ibPreviewMessage_Click(object sender, EventArgs e)
    {        
        ImageButton previewMessage = (ImageButton)sender;
        ClientScriptManager clientScript = Page.ClientScript;
        //string clientScriptName="previewMessage";
        Type clientScriptType=this.GetType();
        int index = previewMessage.ID.IndexOf("_"), ID;
        int.TryParse(previewMessage.ID.Substring(index + 1), out ID);
        foreach (GridDataItem gdi in grdMessages.Items)
        {
            RadTextBox rtb = (RadTextBox)gdi["DefaultDescriptionNameColumn"].FindControl("Description_" + ID.ToString());
            if (rtb != null)
            {
                radWindowManager1.OnClientPageLoad = "OnClientPageLoad('" + HttpUtility.HtmlEncode(rtb.Text) + "')";
                RadWindow newwindow = new RadWindow();
                newwindow.ID = "previewmessages";
                newwindow.NavigateUrl = "about:blank";
                newwindow.VisibleOnPageLoad = true;
                newwindow.Behaviors = WindowBehaviors.Close;
                radWindowManager1.Windows.Add(newwindow);
                  
                //if (!clientScript.IsClientScriptBlockRegistered(clientScriptType, clientScriptName))
                //{
                //    StringBuilder sb = new StringBuilder();
                //    sb.Append("<script type='text/javascript'>");
                //    sb.Append("radopen('about:blank')");
                //    sb.Append("document.write(" + HttpUtility.HtmlEncode(rtb.Text) + ")");
                //    sb.Append("</script>");
                //    clientScript.RegisterClientScriptBlock(clientScriptType, clientScriptName, sb.ToString());
                //}
                //RadAjaxManager ajm = RadAjaxManager.GetCurrent(Page);
                //if (ajm != null)
                //{
                //    ajm.Alert(HttpUtility.HtmlEncode(rtb.Text)); // make this a radopen or a window.open
                //}
            }
        }
    }

    <script type="text/javascript">
        function informationWindowLocation(id) {
            var oManager = GetRadWindowManager();
            var fileName = "Images/" + id;
            var examplePath = new Image();
            examplePath.src = fileName;
            var width = examplePath.width;
            var height = examplePath.height;
            var oWnd = oManager.GetWindowByName("messages");
            if (width > 0 && height > 0) {
                oWnd.Show();
                oWnd.setSize(width + 100, height + 100);
                oWnd.SetUrl(fileName, "messages");
            }
            else {
                radalert("Example doesn't exist for this level and Promotion Type", 425, 150, "Promotion Type Example");
            }
            return false;
        }
        function OnClientPageLoad(textDescription) {
            var oManager = GetRadWindowManager();
            var oWnd = oManager.GetWindowByName("messages");
            oWnd.GetContentFrame().contentWindow.document.write('<html><title>Preview Description</title><body>' + textDescription + '</body></html>');
            oWnd.Show();
        }
    </script>
      
    <telerik:RadGrid ID="grdMessages" runat="server" Skin="Vista" OnItemCreated="grdMessages_ItemCreated" style="padding-top:20px;">
      <ItemStyle Height="150px" />
      <MasterTableView AutoGenerateColumns="false" ShowHeader="false" DataKeyNames="Level" ClientDataKeyNames="Level" EnableNoRecordsTemplate="true">
        <Columns>          
          <telerik:GridBoundColumn DataField="Level" UniqueName="LevelColumn" Visible="false" />
          <telerik:GridTemplateColumn UniqueName="ShowImage" DataField="Level_Message_Example">
             <ItemTemplate>
               <asp:ImageButton ID="ibPreviewLocation" runat="server" ImageUrl="~/Images/picture.png" ImageAlign="Middle" OnClientClick='<%# String.Format("return informationWindowLocation(\"{0}\");", Eval("Level_Message_Example")) %>' />
             </ItemTemplate>
          </telerik:GridTemplateColumn>
          <telerik:GridTemplateColumn UniqueName="PreviewMessage" DataField="Level">
             <ItemTemplate>
               <asp:ImageButton ID="ibPreviewMessage" runat="server" ImageUrl="~/Images/image_magnify.png" ImageAlign="Middle" OnClick="ibPreviewMessage_Click" />
             </ItemTemplate>
          </telerik:GridTemplateColumn>
          <telerik:GridBoundColumn DataField="Description" UniqueName="DescriptionColumn" />
          <telerik:GridTemplateColumn DataField="Default_Description" UniqueName="DefaultDescriptionNameColumn">
            <ItemStyle Width="70%" Wrap="false" Height="150px" />
            <ItemTemplate>
              <telerik:RadTextBox ID="rtbDescription" Height="150px" runat="server" Width="100%" TextMode="MultiLine" Text='<%# Eval("Default_Description") %>' /> 
            </ItemTemplate>
          </telerik:GridTemplateColumn>          
        </Columns>      
        <NoRecordsTemplate><asp:Label ID="lblPromotionEmptyMessage" runat="server" Text="No Messages Available for Editing" /></NoRecordsTemplate>  
      </MasterTableView>
    </telerik:RadGrid>
    <telerik:RadWindowManager ID="radWindowManager1" runat="server"></telerik:RadWindowManager>

    the radwindow manager on the aspx page looks like this
    <telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="false" VisibleStatusbar="false"
        ReloadOnShow="true" runat="server" Skin="Windows7" EnableShadow="true" Behaviors="Close">
        <Windows>
            <telerik:RadWindow ID="save" runat="server" Skin="Windows7" Height="345px" Width="475px"
                ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" VisibleTitlebar="false" />
            <telerik:RadWindow ID="products" Width="320" Height="275" runat="server" Behaviors="Close" />
            <telerik:RadWindow ID="messages" runat="server" KeepInScreenBounds="true" Behaviors="Close" Width="300" Height="300" />            
        </Windows>
    </telerik:RadWindowManager>

    I know that it has two radwindowmanagers on the same page, but I couldn't get the manager from the main page when I tried to search using the $find method. I also couldn't find the one on the user control. Let me know if there is anything I should do. Thanks
  2. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 18 Nov 2010 Link to this post

    Hi Alex,

    The OnClientPageLoad property accepts the name of the JavaScript function only, not the function itself.
    e.g. the correct way to set it is OnClientPageLoad="OnClientPageLoadFunction" where OnClientPageLoadFunction is the name of the JavaScript function that you want to fire. With your current code (OnClientPageLoad="OnClientPageLoad(someArgument)") the JS function will be automatically fired when it is rendered on the page and it will cause an error as the manager itself is not fully rendered.

    Best wishes,
    Georgi Tunev
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. Alex
    Alex avatar
    31 posts
    Member since:
    Jun 2009

    Posted 18 Nov 2010 Link to this post

    So how do I get to the point where I can pass in the name of the control once the names have been set, find it via javascript, and once a button is clicked on a row, it fires the window off previewing what is in the text box?
  4. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 23 Nov 2010 Link to this post

    Hi Alex,

    I examined your current code and tried to build a test demo based on it. However, since you return false from the client handler, the server button handler is never executed on my side. I am also not suer about your exact idea. Could you please provide more detailed explanations about the following:

    1) What is your exact goal?
    2) What is the exact sequence of things you want to achieve when the button is clicked? Do you want to perform the postback first and then execute client code? Or you want to execute the client code and them depending on a condition make a postback? Is AJAX request a solution for your case (note that it makes a big difference considering global js variables you could use) ? Do you really need to go to the server or all you need is the content of the textbox?

    Once I get a better understanding on your exact requirements and scenario I will do my bets to help.


    Kind regards,

    Svetlina
    the Telerik team

     

    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  5. Alex
    Alex avatar
    31 posts
    Member since:
    Jun 2009

    Posted 23 Nov 2010 Link to this post

    Hi Svetlina,
      1) My exact goal is as follows: The ability to preview the content of a RadTextBox in a pop up window. For instance, if there is 
          html in the textbox, I'd like to show it as sort of a "preview" what is being submitted.
      2) The exact sequence I'd like to achieve (just the way it makes sense to me) when the button is clicked is as follows. Gather the
          value within the textbox, take that content and initiate some sort of RadWindow that will allow me to show the message. It doesn't 
          matter to me about postbacks or AJAXification of my controls. This is within a tab view and other controls affect the whole 
          multipage  view, so it is equipped to deal with AJAX or posting back. I don't need to go to a server level, it just seemed as though it 
          was the easiest solution at the time.


    Does that answer all of your questions? If you have anything else to ask, please don't hesitate to reply. Thanks!

     ~~ Alex
  6. Answer
    Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 25 Nov 2010 Link to this post

    Hello Alex,

     Thank you for the provided additional details, they helped me understand your scenario. In this case I believe that the best solution regarding performance and clean code is to use a custom attribute to extract the value. Since this solution is more complex than others but avoids round trip to the server it is the better one in this case, For your convenience I implemented it in a demo page based on your code and you can find it attached. In the demo page, when you click on the first column's image button, a RadWindow with the text of the corresponding RadTextBox is opened. If you close the window, change the text and reopen it, it will reflect the change.

    I hope that my reply is helpful, let me know how it goes.

    Kind regards,
    Svetlina
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top