On Demand Loading of a control

I currently have a asp.net page that has an Infragistics control on it.  The control's page load event fires before the parent page load event.  My problem is that the parent page needs to save data and then set a session variable which passes to the control, but due to the fact that the control loads first, the session variable never gets set.  Is there a way to not load the control and call it after the savedata method on the parent page?
sstoosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tusharashahCommented:
You can dynamically load the UserControl whenever you want... or after you sessions are initialize:


Add this line in your ASPX HTML
<%@ Reference Control = "UserControl1.ascx" %>


And then in code Add this after you initialize sessions

UserControl1 uc1 = (UserControl1) Page.LoadControl("UserControl1.ascx");
PlaceHolder1.Controls.Add(uc1);

-tushar
0
tusharashahCommented:
OR if you want to avoid loading Controls dynamically you can use this workaround:

.. Page_Load(..)
{
   if( Session["YourSessionName"] == null )
   {
       Session["YourSessionName"] = "SetSession";
       Response.Redirect( Request.RawUrl );
   }
}

-tushar
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sstoosAuthor Commented:
Ok...I'm a little new on this concept. I'm using vb so I assume I declare the control in the declarations as control, right. Then what do you mean by Placeholder1?  Also, what is uc1 referencing?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

tusharashahCommented:
You can declare it as the way I showed.

Then what do you mean by Placeholder1?
--> PlaceHolder1 is WebControl if you BrowsYour WebControl you'll see "PlaceHolder" in them.
--> Drag and drop PlaceHolder1 wherever you want to put your UserControl

UC1
--> UserControl1 is the Name of you Control and uc1 is Object of that control

But, I think the 2nd option will be lot easier to deal with if you can adapt that..

-tusahr
0
sstoosAuthor Commented:
So if I was to use the second option....sorry to be so dense, but what does "Response.redirect(request.RawURL) do?  And this code would reside in the ascx page load???
0
tusharashahCommented:
Response.Redirect  : Will Redirect you to URL that is passed as Argument
Request.RawUrl      : Will Give you current URL of page.

You need call Response.Redirect( Request.RawUrl ) after you have Set your Session variable.

"the parent page needs to save data and then set a session variable which passes to the control"
--> Set Session Variable and then use Response.Redirct to Re-load page

.. Page_Load(..)
{
   if( Session["YourSessionName"] == null )
   {
       SaveData();
       Session["YourSessionName"] = "SetSession";
       Response.Redirect( Request.RawUrl );
   }
}

ps. You should always check that Session Variable are not null before using them anywhere.

-tushar
0
sstoosAuthor Commented:
The only disadvantage that I can see with this, is that the control will still load first and am trying to get around that, if possible.
0
tusharashahCommented:
Alright in that case
- Put PlaceHolder/Panel wherever you want to show UserControl
- After you Set your session add following line:

Dim uc1 As UserControl1 = CType(Page.LoadControl("UserControl1.ascx"), UserControl1)
PlaceHolder1.Controls.Add(uc1)

[ Replace UserControl1 with name of your UserControl.
     i.e. if your UserControl is Header.ascx then replace "UserControl1" with "Header" ]

-tushar
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.