Opening radwindow from registerstartupscript, can't pass parameter

3 posts, 1 answers
  1. Garrett
    Garrett avatar
    35 posts
    Member since:
    Feb 2012

    Posted 10 Jun 2014 Link to this post

    Here is my javascript:

    <script type="text/javascript">
        function ShowWindow(dealid) {
            
            var oWnd = window.radopen('Windows/DealReassignmentPopup.aspx', 'window1');
        }
    </script>

    and my code behind:

    protected void gridAssignSingleDeal_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
                if (e.CommandName == "OpenWindow")
            {
                int datakeyvalue = Helper.IntHelper((e.Item as GridDataItem).GetDataKeyValue("ID"));
       
               string script = string.Format("<script language='javascript' type='text/javascript'>Sys.Application.add_load(ShowWindow({0}));</script>",datakeyvalue);
                ClientScript.RegisterStartupScript(this.GetType(), "showWindow", script);
                            
            }
        }


    If I do not pass it any parameters ( take out string.format) it works. If I try to pass it a parameter, it does not, it says this error:

    Unhandled exception at line 17467, column 1 
    0x800a138f - JavaScript runtime error: Unable to get property 'open' of undefined or null reference





    All I want to do is have a button on my grid that when I click it, it opens a radwindow with a parameter. If I have to do this another way, I am up for that.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Jun 2014 in reply to Garrett Link to this post

    Hi Garrett,

    Please modify the C# code snippet as follows which works fine at my end.

    C#:
    protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == "OpenWindow")
        {
            int datakeyvalue = Convert.ToInt32((e.Item as GridDataItem).GetDataKeyValue("OrderID"));
            string script = "function f(){ShowWindow('" + datakeyvalue + "'); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
        }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Garrett
    Garrett avatar
    35 posts
    Member since:
    Feb 2012

    Posted 10 Jun 2014 in reply to Shinu Link to this post

    You are the best Shinu, you always fix my issues, thanks!
Back to Top