Rad window on checking a filed..

14 posts, 1 answers
  1. Prashanth
    Prashanth avatar
    13 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    Hi Friends,

    I am new to this forum i am working on a project. where A Button click("Show Activity Button") should open a Rad window . In that Rad Window there are four checkBoxes which come from DataBase if we check "Development"( Attached File img1.png) It should go back to the parent page and display what it is there in the attached file "img2.png". If we multi check the Check boxes it should display the fields accordingly. And when we click on Submit button in the parent page it should send it to the database .

    Please help me out.

  2. Prashanth
    Prashanth avatar
    13 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    I don't know how to do this ... Anyone please help me out ...
  3. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Aug 2012 Link to this post

    Hi Prashanth,

    You can get the the values from the ChildWindow as follows.

    Parent Window

    ASPX:
    <telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="false" VisibleStatusbar="false"
       ReloadOnShow="true" runat="server" Skin="Sunset" EnableShadow="true">
       <Windows>
          <telerik:RadWindow ID="RadWindow1" runat="server" Behaviors="Close" OnClientClose="OnClientClose" NavigateUrl="ChildWindow.aspx">
          </telerik:RadWindow>
       </Windows>
      </telerik:RadWindowManager>
    <asp:Button ID="Button1" runat="server" OnClientClick="openWin(); return false;" />

    Javascript:
    <script type="text/javascript">
     function openWin()
       {
          var oWnd = radopen("ChildWindow.aspx", "RadWindow1");
       }
     function OnClientClose(oWnd, args)
       {
         //get the transferred arguments
         var arg = args.get_argument();
         if (arg)
         {
          var Checkox1 = arg.one;
          var Checkox2 = arg.two;
          var Checkox3 = arg.three;
         }
       }
    </script>

    ChildWindow 

    ASPX:
    <asp:CheckBox ID="CheckBox1" Text="1" runat="server" />
    <asp:CheckBox ID="CheckBox2" Text="2" runat="server" />
    <asp:CheckBox ID="CheckBox3" Text="3" runat="server" />
    <asp:Button ID="Submit" runat="server"  OnClientClick="returnToParent(); return false;" />

    Javascript:
    <script type="text/javascript">
      function GetRadWindow()
      {
        var oWindow = null;
        if (window.radWindow) oWindow = window.radWindow;
        else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
        return oWindow;
      }
      function returnToParent()
      {
       var oArg = new Object();
       oArg.one = document.getElementById("CheckBox1").checked;
       oArg.two = document.getElementById("CheckBox2").checked;
       oArg.three = document.getElementById("CheckBox3").checked;
       var oWnd = GetRadWindow();
       oWnd.close(oArg);
      }
    </script>

    Hope this helps.

    Thanks,
    Princy.
  4. Prashanth
    Prashanth avatar
    13 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    Hi Princy,
    Thanks for the Post i will check and get back to you immediately...
  5. Prashanth
    Prashanth avatar
    13 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    Hi Princy,

    I  checked with your code....I am not getting back the values from the child window by the way i want it in CheckBoxList with database values..Once please check my attached files i want the things to happen like that... please help me out...
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Aug 2012 Link to this post

    Hi Prashanth,

    I suppose you need to get the values in the server side. You can achieve this by setting value in a hiddenfield from clientside and firing a buttonclick as follows.

    ASPX:
    <asp:Button ID="Button1" runat="server" Text="Open Window" OnClientClick="openWin(); return false;" />
    <asp:HiddenField ID="HiddenField1" runat="server" />
    <asp:HiddenField ID="HiddenField2" runat="server" />
    <asp:HiddenField ID="HiddenField3" runat="server" />
    <asp:Button ID="Button2" runat="server" CssClass="hiddenButton" onclick="Button2_Click" />

    Javascript:
    function OnClientClose(oWnd, args)
    {
       //save the transferred arguments
       var arg = args.get_argument();
       if (arg)
       {
        document.getElementById("HiddenField1").value = arg.one;
        document.getElementById("HiddenField2").value = arg.two;
        document.getElementById("HiddenField3").value = arg.three;
        document.getElementById("Button2").click();
        }
    }

    C#:
    protected void Button2_Click(object sender, EventArgs e)
        {
            string checkbox1 = HiddenField1.Value;
            string checkbox2 = HiddenField2.Value;
            string checkbox3 = HiddenField3.Value;
            //  Your Code
        }

    Please provide your full code if this doesn't helps.

    Thanks,
    Princy.
  7. Prashanth
    Prashanth avatar
    13 posts
    Member since:
    Aug 2012

    Posted 14 Aug 2012 Link to this post

    Hi Princy,
     This is my Complete code

    Parent.aspx:
    <telerik:RadWindow ID="RadWindow1" runat="server" MaxHeight="300px"
                        MaxWidth="300px" MinHeight="300px" MinWidth="400px" Modal="True"
                        OpenerElementID="Button3" Title="Select Activities"
                        ToolTip="Select One or More Activities" VisibleStatusbar="False"
                        Width="400px" NavigateUrl="child.aspx" Skin="Default"
                        onclientclose="OnClientClose" ReloadOnShow="True">
      </telerik:RadWindow>
    <asp:Button ID="Button1" runat="server" Text="Select Activity"
                         style="height: 26px" onclick="Button1_Click" />
    In Rad Window Properties i have written Navigation: 'child.aspx', OnClientClose: 'OnClientClose'

    I dont know how to put JavaScript because it is taking Four Values

    Parent.aspx.cs:
    protected void Button1_Click(object sender, EventArgs e)
            {
                RadWindow1.VisibleOnPageLoad = true;
                 
            }


    child.aspx
    <strong>Activities Done</strong>
            <asp:CheckBoxList ID="CheckBoxList1" runat="server"
                DataSourceID="SqlDataSource1" DataTextField="Activity"
                DataValueField="Activity">
            </asp:CheckBoxList>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:HumanResourceConnectionString %>"
                SelectCommand="SELECT [Activity] FROM [tsmActivity]"></asp:SqlDataSource>
            <asp:Button ID="Button2" OnClientClick="CloseWindow(); return false;" runat="server" Text="Select"/>


    Javascript:

    <script type="text/javascript">
        function CloseWindow() {
            var cur = getra();
            var result = document.getElementById('CheckBoxList1').checked;
            cur.argument = result;
            cur.close();
        }
        function getra() {
            var win = null;
            if (window.radWindow)
                win = window.radWindow;
            else if (window.frameElement.radWindow)
                win = window.frameElement.radWindow;
            return win;
        }
    </script>


    No .cs file for child page
  8. Prashanth
    Prashanth avatar
    13 posts
    Member since:
    Aug 2012

    Posted 14 Aug 2012 Link to this post

    Hi Princy,

    Look Into My Code and Please Help me out.
  9. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Aug 2012 Link to this post

    Hi Prashanth,

    You can get the values of checked checkboxes in an array and send it as a Json string as follows.

    Child Window 

    Javascript:
    <script type="text/javascript">
     function returnToParent()
     {
      var oArg = new Object();
      var options = document.getElementById("CheckBoxList1").getElementsByTagName('input');
      var optionsArray = new Array();
      var index = 0;
      for (i = 0; i < options.length; i++)
      {
       var opt = options[i];
       if (opt.type == "checkbox")
       {
        if (opt.checked)
        {
         optionsArray[index] = opt.value;
         index++;
        }
       }
      }
      oArg.data = JSON.stringify(optionsArray);
      var oWnd = GetRadWindow();
      oWnd.close(oArg);
     }
    </script>

    Parent Window

    Javascript:
    <script type="text/javascript">
    function OnClientClose(oWnd, args)
    {
     //get the transferred arguments
     var arg = args.get_argument();
     if (arg)
     {
      document.getElementById("HiddenField1").value = arg.data;
      document.getElementById("Button2").click();
     }
    }
    </script>

    C#:
    protected void Button2_Click(object sender, EventArgs e)
    {
     var jss = new JavaScriptSerializer();
     var values = jss.Deserialize<string[]>(HiddenField1.Value);
    }

    Hope this helps.

    Thanks,
    Princy.
  10. Prashanth
    Prashanth avatar
    13 posts
    Member since:
    Aug 2012

    Posted 21 Aug 2012 Link to this post

    hi princy,
    I looked into your code but there are no textboxes in it...as i told in my 1st post(please look into the attached files) and i want them exactly what it is in that image.....please help me out..
  11. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Aug 2012 Link to this post

    Hi Prashanth,

    One suggestion is that you can add a table control and dynamically add rows and cells to it as follows.

    ASPX:
    <asp:Table ID="tblDevelopement" Visible="false" runat="server"></asp:Table>

    C#:
    protected void Button2_Click(object sender, EventArgs e)
    {
     var jss = new JavaScriptSerializer();
     var values = jss.Deserialize<string[]>(HiddenField1.Value);
     int pos = Array.IndexOf(values, "Developement");
     if(pos > -1) // Checking whether Developement has been Checked
      {
       tblDevelopement.Visible = true;
       TableRow tRowLabel = new TableRow();
       TableRow tRowTextBox = new TableRow();
       DayOfWeek day = DateTime.Now.DayOfWeek;
       int days = day - DayOfWeek.Monday;
       DateTime start = DateTime.Now.AddDays(-days);
       DateTime end = start.AddDays(6);
       DateTime loopDate = new DateTime();
       loopDate = start;
       for (int i = 0; i < 7; i++)
       {
        TableCell tCellLabel = new TableCell();
        TableCell tCellTextBox = new TableCell();
        Label lbl = new Label();
        lbl.Text = loopDate.Date.ToString("ddd d");
        TextBox txt = new TextBox();
        txt.ID = "Developement" + i;
        if (loopDate > DateTime.Now)
        {
         txt.Enabled = false;
        }
        else if (loopDate < DateTime.Now)
        {
         txt.Text = "data"; // Get Data From Database
        }
        tCellLabel.Controls.Add(lbl);
        tCellTextBox.Controls.Add(txt);
        tRowLabel.Cells.Add(tCellLabel);
        tRowTextBox.Cells.Add(tCellTextBox);
        loopDate = loopDate.AddDays(1);
      }
      tblDevelopement.Rows.Add(tRowLabel);
      tblDevelopement.Rows.Add(tRowTextBox);
     }
    }

    Thanks,
    Princy.
  12. Prashanth
    Prashanth avatar
    13 posts
    Member since:
    Aug 2012

    Posted 23 Aug 2012 Link to this post

    If possible can u send the complete code from scratch...
  13. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Aug 2012 Link to this post

    Hi Prashanth,

    Here is the full code that I tried based your scenario.

    ParentPage

    ASPX:
    <telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="false" VisibleStatusbar="false" ReloadOnShow="true" runat="server" Skin="Sunset" EnableShadow="true">
     <Windows>
       <telerik:RadWindow ID="RadWindow1" runat="server" Behaviors="Close" OnClientClose="OnClientClose" NavigateUrl="RvalueSecond.aspx">
       </telerik:RadWindow>
     </Windows>
    </telerik:RadWindowManager>
     
    <asp:Button ID="Button1" runat="server" Text="Open Window" OnClientClick="return openWin();"  />
    <asp:Table ID="tblDevelopement" Visible="false" runat="server"></asp:Table>
    <asp:HiddenField ID="HiddenField1" runat="server" />
    <asp:Button ID="Button2" runat="server" CssClass="hiddenButton" onclick="Button2_Click" />

    Javascript:
    <script type="text/javascript">
     function openWin()
     {
      var oWnd = radopen("RvalueSecond.aspx", "RadWindow1");
      return false;
     }
     
     function OnClientClose(oWnd, args)
     {
      //get the transferred arguments
      var arg = args.get_argument();
      if (arg)
      {
       document.getElementById("HiddenField1").value = arg.data;
       document.getElementById("Button2").click();
      }
     }
    </script>
    C#:
    protected void Button2_Click(object sender, EventArgs e)
    {
     var jss = new JavaScriptSerializer();
     var values = jss.Deserialize<string[]>(HiddenField1.Value);
     int pos = Array.IndexOf(values, "Developement");
     if(pos > -1)
      {
       tblDevelopement.Visible = true;
       TableRow tRowLabel = new TableRow();
       TableRow tRowTextBox = new TableRow();
       DayOfWeek day = DateTime.Now.DayOfWeek;
       int days = day - DayOfWeek.Monday;
       DateTime start = DateTime.Now.AddDays(-days);
       DateTime end = start.AddDays(6);
       DateTime loopDate = new DateTime();
       loopDate = start;
       for (int i = 0; i < 7; i++)
       {
        TableCell tCellLabel = new TableCell();
        TableCell tCellTextBox = new TableCell();
        Label lbl = new Label();
        lbl.Text = loopDate.Date.ToString("ddd d");
        TextBox txt = new TextBox();
        txt.ID = "Developement" + i;
        if (loopDate > DateTime.Now)
        {
         txt.Enabled = false;
        }
        else if (loopDate < DateTime.Now)
        {
         txt.Text = "data"; // Get Data From Database
        }
        tCellLabel.Controls.Add(lbl);
        tCellTextBox.Controls.Add(txt);
        tRowLabel.Cells.Add(tCellLabel);
        tRowTextBox.Cells.Add(tCellTextBox);
        loopDate = loopDate.AddDays(1);
      }
      tblDevelopement.Rows.Add(tRowLabel);
      tblDevelopement.Rows.Add(tRowTextBox);
     }
    }

    Child Page

    ASPX:
    <asp:CheckBoxList ID="CheckBoxList1"  runat="server" DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="id" ></asp:CheckBoxList>
    <asp:Button ID="Submit" runat="server"  OnClientClick="returnToParent(); return false;" />

    Javascript:
    <script type="text/javascript">
     function GetRadWindow()
     {
      var oWindow = null;
      if (window.radWindow) oWindow = window.radWindow;
      else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
      return oWindow;
     }
     function returnToParent()
     {
      var oArg = new Object();
      var options = document.getElementById("CheckBoxList1").getElementsByTagName('input');
      var optionsArray = new Array();
      var index = 0;
      for (i = 0; i < options.length; i++)
      {
       var opt = options[i];
       if (opt.type == "checkbox")
       {
        if (opt.checked)
        {
         optionsArray[index] = opt.value;
         index++;
        }
       }
      }
     oArg.data = JSON.stringify(optionsArray);
     var oWnd = GetRadWindow();
     oWnd.close(oArg);
    }
    </script>

    Thanks,
    Princy.
  14. Prashanth
    Prashanth avatar
    13 posts
    Member since:
    Aug 2012

    Posted 01 Sep 2012 Link to this post

    Hi Princy,

    The Code which you have given Worked perfectly in a New project. But if i copy the same code and paste in my solution file i am getting an error "Microsoft JScript runtime error: Unable to set value of the property 'value': object is null or undefined". which is located at "document.getElementbyId("TextBox1").value=arg.data; "
Back to Top