Method not firing
-
Dear all, I use the code below for firing a method, however .. it's not firing. I use the same piece of code (different class though) a little further in my application and it's working fine.
protected void Page_Load(object sender, EventArgs e)
{
Control ce = LoadControl("TimeEntry.ascx");
pnlProjects.Controls.Add(ce);foreach(Control ctl in pnlProjects.Controls) if (ctl.GetType() == typeof(TimeEntry)) { TimeEntry te = (TimeEntry)ctl; te.LoadControls(); } }
I don't want to put
LoadControls();
in my Page_Load of TimeEntry.ascx because it's posting back when I navigate away from the page and thus firing the method again. Can any tell me what I am doing wrong. Kind regards,
-
Dear all, I use the code below for firing a method, however .. it's not firing. I use the same piece of code (different class though) a little further in my application and it's working fine.
protected void Page_Load(object sender, EventArgs e)
{
Control ce = LoadControl("TimeEntry.ascx");
pnlProjects.Controls.Add(ce);foreach(Control ctl in pnlProjects.Controls) if (ctl.GetType() == typeof(TimeEntry)) { TimeEntry te = (TimeEntry)ctl; te.LoadControls(); } }
I don't want to put
LoadControls();
in my Page_Load of TimeEntry.ascx because it's posting back when I navigate away from the page and thus firing the method again. Can any tell me what I am doing wrong. Kind regards,
You can put the LoadControls in Page_Load but with below condition :
If(!IsPostback)
LoadControls()This will cause the LoadControls to call only at the first loading of the page and not everytime postback occurs. IsPostBack property is used to check whether the page is getting loaded first time of the postback caused by any control on the page. Hope this helps. All the best.
I quit being afraid when my first venture failed and the sky didn't fall down.