How to find RadGrid in usercontrol from .aspx page

2 posts, 0 answers
  1. Salman
    Salman avatar
    1 posts
    Member since:
    Nov 2013

    Posted 19 Nov 2013 Link to this post

    Hello...

    I have a Radgrid inside user control & I want to find it from aspx page server side. I have written the following code for it but shows me error $find()...is null....

    Can anyone please help me asap?

    Usercontrol.ascx

    function RadGridRow() {
         return $find("<%=RGOrders.ClientID %>").get_masterTableView().get_dataItems();
    }

    Page.aspx

    function abc() {
         var RgOrders = RadGridRow();
    }

    Please note that I am calling the function abc() from server-side (code - behind). From client side, this function is working fine

    Page.aspx.cs

    string strscript = "abc();";
    ScriptManager.RegisterStartupScript(pnl, pnl.GetType(), "ShowMessage" + DateTime.Now.ToLongTimeString(), strScript, true);
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Nov 2013 Link to this post

    Hi Salman,

    Please have a look into the following code snippet to call a client side function from the server side and access the RadGrid in UserControl From the ASPX page.

    ASPX C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        //call the client side function of the aspx page
        string script = "function f(){abc(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);  
    }

    ASPX JavaScript:
    <script type="text/javascript">
        function abc() {
            var RgOrders = RadGridRow();
        }
    </script>

    ASCX JavaScript:
    <script type="text/javascript">
        function RadGridRow() {
            return $find("<%=RadGrid1.ClientID %>").get_masterTableView().get_dataItems();
        }
    </script>

    Thanks,
    Shinu.
Back to Top