title: How to call a function from another .aspx page before the page_load() in asp.net?
body: <p>I have a aspx page called test.aspx that inherits a master page.The master page has usercontrol file called lcont.ascx which has a treeview whose node is populated with data from database and a  contentpalceholder.</p>
  
  <p>The contentplaceholder is where i want to display data from database according to the treenode clicked and so has a Datalist defined within it.Its corresponding .cs file gives the sqlconnection and query to display data in page_load.</p>
  
  <p>So whenever I click the treenode in the test.aspx , the page_load of its corresponding .cs file is called.But what i want is to call .cs file of usercontrol file lcont.ascx so that i can pass the id to query in .cs file of test.aspx.cs.</p>
  
  <p>Is it possible to call function from another page before page_load?
  Or is it possible to go to .cs file of another file before going through its own .cs file?</p>
  
  <p>Here is the code from lcont.ascx.cs</p>
  
  <pre><code>   protected void my_tv_SelectedNodeChanged(object sender, EventArgs e)
     {
      TreeView tv = sender as TreeView;
      var selectedN = tv.SelectedNode;
  
      if (selectedN.Parent != null)
      {
          var id = tv.SelectedNode.Value;
          var name = tv.SelectedNode.Text;
          //Session["mySvar"] = id;
  
          ScriptManager.RegisterStartupScript(this, this.GetType(), "nething", "show("+id+")", true);
      }
      else
      {
          //Response.Redirect("test.aspx");
      }
  
  
    }
  </code></pre>
  
  <p>I want to call this function before the page_load of test.aspx.cs file.</p>
  
  <p>The code of test.aspx.cs file is</p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
   {
      display();  
   }
  
  public void display()
  {
  
      string str = hdn.Value;
      slbl.Text = "value is" + str;
      //var a = Session["mySvar"];
      var a = 2;
      sq.connection();
      SqlCommand cmd = new SqlCommand("select * from sub_catTbl where sid='" + a + "' ", sq.con);
      SqlDataReader sd = cmd.ExecuteReader();
  
      mydatalist.DataSource = sd;
      mydatalist.DataBind();
      sq.con.Dispose();
      sq.con.Close();
  }
  </code></pre>
  
  <p>I need to call the function before this page_load call so that i can give sid = "variable value that i obtain after clicking the treenode that is available in lcont.ashx.cs"</p>