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

Multiple Windows Incorrectly Sharing Passed In Variable

1 Answer 15 Views
Window
This is a migrated thread and some comments may be shown as answers.
Andrew Galea
Top achievements
Rank 1
Andrew Galea asked on 26 Jul 2012, 09:17 AM
Hello,

I am implementing RadWindow in a user control that will pop up context sensitive help whenever the user clicks an icon.  The intention is that I will drop the user control anywhere on a page that requires it (i.e. multiple instances on the one page).

I have set up a hidden field on the user control so that each time it is dropped onto the page I can set the value of the field which is then used by the control to determine which help data to load.

The problem is that it seems the window the control uses is shared across all instances and it is unable to store the value independent of one another (therefore the same help text appears each time regardless of which help control is clicked).

Here is my Help Control code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Help.ascx.cs" Inherits="Controls_Generic_Help" %>
<script type="text/javascript">
    function openHelpWindow(sender, args) {          
        var radWindow = $find("<%=radWindow1.ClientID%>");
        var docId = $get("<%= documentIdField.ClientID%>").value;
        radWindow.setUrl("help.aspx?Id=" + docId);
        radWindow.show();
    }
</script>
<telerik:RadButton id="helpButton" runat="server" autopostback="false" Width="16" Height="16" onclientclicked="openHelpWindow">
    <Image EnableImageButton="true" ImageUrl="~/images/icon-help.png" IsBackgroundImage="false" />
</telerik:RadButton>
<telerik:radwindow id="radWindow1" runat="server" Width="600px" Height="600px" VisibleTitlebar="false"></telerik:radwindow>
<asp:HiddenField runat="server" ID="documentIdField" />


Then all I do on the page where the control is dropped is set the hidden field value:
Help1.HelpDocName = "HelpQuickLinksNavigator";
 
Help2.HelpDocName = "HelpActivityFeed";

However all that happens is that the first value only is used each time the window is opened.

Thoughts?

Andrew

1 Answer, 1 is accepted

Sort by
0
Andrew Galea
Top achievements
Rank 1
answered on 26 Jul 2012, 10:29 AM
Ok I managed to get this to work.

I am still not 100% sure on why I was getting the issue however I tried an alternative approach to the problem and it works perfectly now.

For those that are interested here is the new code for the Help control:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Help.ascx.cs" Inherits="Controls_Generic_Help" %>
<asp:ImageButton runat="server" ID="helpButton" ImageUrl="~/Images/icon-help.png" Width="16" Height="16" BorderWidth="0"/>
<asp:HiddenField runat="server" ID="documentIdField" />
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    <Windows>
        <telerik:RadWindow
            id="RadWindow1"
            runat="server"
            showcontentduringload="false"
            width="600px"
            height="600px"
            behaviors="Default"
            VisibleTitlebar="False"
            VisibleStatusbar="False">
        </telerik:RadWindow>
    </Windows>
</telerik:RadWindowManager>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        //<![CDATA[
        function openRadWin(url) {
            radopen(url, "RadWindow1");
        }
        //]]>                                                                       
    </script>
</telerik:RadCodeBlock>
So basically I dropped a RadWindowManager onto the page and replaced the javascript with a simpler version in a RadCodeBlock.  The RadButton was replaced with an ImageButton that was given the following attribute in the code behind on load:
using System;
using RankingsHQ.Utils;
 
public partial class Controls_Generic_Help : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            var baseUrl = Request.Url.AbsoluteUri.ToLower().Substring(0,
                                                                      Request.Url.AbsoluteUri.ToLower().IndexOf(
                                                                          Request.Url.PathAndQuery.ToLower()));
            //helpButton.Attributes.Add("OnClick", "openRadWin('" + absoluteUri.Substring(0, absoluteUri.IndexOf("public")) + "/help.aspx?Id=" + documentIdField.Value + "');return false;");
            if(EnvironmentManager.CurrentEnvironment == EnvironmentManager.Environment.Local)
            {
                helpButton.Attributes.Add("OnClick", "openRadWin('" + baseUrl + "/website/help.aspx?Id=" + documentIdField.Value + "');return false;");  
            }               
            else
            {
                helpButton.Attributes.Add("OnClick", "openRadWin('" + baseUrl + "/help.aspx?Id=" + documentIdField.Value + "');return false;");
            }
        }
    }
    public string HelpDocName
    {
        set { documentIdField.Value = value; }
    }
}
So as you can see I set the OnClick attribute dynamically based on the value in the hidden field.

This all works as intended giving me context sensitive help through my website by simply dropping a user control where I want the help icon to appear and setting the document name for each Help UserControl on the page during load.

Regards,
Andrew
Tags
Window
Asked by
Andrew Galea
Top achievements
Rank 1
Answers by
Andrew Galea
Top achievements
Rank 1
Share this question
or