[CLOSED] Calling a UserControl Direct Event method from a different page

  1. #1

    [CLOSED] Calling a UserControl Direct Event method from a different page

    We are calling theusercontrol's direct event method from a different cs file. However we cannot assign a Session Value on the direct event method.
    Please look at the code.
    //This is the cs file calling the usercontrol
    
     Ext.Net.Button btnSee = ((Ext.Net.Button)ucGrid1.getGrid.BottomBar[0].Items[0]);
                btnSee.DirectClick += new UserControl_VPNSurec().seePDFForm;
                btnSee.DirectEvents.Click.ExtraParams.Add(new Ext.Net.Parameter { Name = "Values", Value = "Ext.encode(#{Grid1}.getRowsValues({selectedOnly : false}))", Mode = ParameterMode.Raw });
    //This is the code behing on user control page
    
    public void seePDFForm(object sender, DirectEventArgs e)
        {
            string json = e.ExtraParams["Values"];
            Dictionary<string, string>[] selectedVal = JSON.Deserialize<Dictionary<string, string>[]>(json);
            int formid = Convert.ToInt32((selectedVal[0]["formid"]).ToString());
            Session[SystemVariables.VPN_FORM_ID] = formid;   //The program fails here error is Session is NULL - Null reference exception
     
    
        }
    Last edited by Daniil; Mar 15, 2011 at 7:54 AM. Reason: [CLOSED]
  2. #2
    Hi,

    It's required to add a user control in controls collection, like this:
    Work.TestUC uc = new Work.TestUC();
    this.Form.Controls.Add(uc);
    Here is a full example:

    Example Page
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Import Namespace="Work" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
    Work.TestUC uc = new Work.TestUC();
    this.Form.Controls.Add(uc);
    
            Ext.Net.Button btnSee = new Ext.Net.Button()
            {
                Text = "Click me",
            };
            btnSee.DirectClick += uc.seePDFForm;
            
            this.Form.Controls.Add(btnSee);
    
            this.Session["test"] = "Hello World!";
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        </form>
    </body>
    </html>
    Example User Control
    <%@ Control 
        Language="C#" 
        CodeBehind="TestUC.ascx.cs" 
        Inherits="Work.TestUC" %>
    
    using Ext.Net;
    
    namespace Work
    {
        public partial class TestUC : System.Web.UI.UserControl
        {
            public void TestDirectHandler(object sender, DirectEventArgs e)
            {
                X.Msg.Alert("DirectEvent", this.Session["test"]).Show();
            }
        }
    }

Similar Threads

  1. [CLOSED] Output Cache issue with Direct Method / Direct Event
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 18
    Last Post: Mar 01, 2013, 5:03 AM
  2. Replies: 0
    Last Post: Mar 08, 2012, 9:45 AM
  3. Replies: 2
    Last Post: Oct 12, 2011, 7:49 AM
  4. Success function in calling Direct Method..help!
    By Aleksa007 in forum 1.x Help
    Replies: 2
    Last Post: Jul 26, 2011, 4:36 PM
  5. Replies: 2
    Last Post: Apr 27, 2011, 2:58 PM

Posting Permissions