[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

On Demand Loading of a control

Posted on 2004-11-03
8
Medium Priority
?
341 Views
Last Modified: 2006-11-17
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?
0
Comment
Question by:sstoos
  • 5
  • 3
8 Comments
 
LVL 18

Expert Comment

by:tusharashah
ID: 12487401
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
 
LVL 18

Accepted Solution

by:
tusharashah earned 2000 total points
ID: 12487516
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
 

Author Comment

by:sstoos
ID: 12487692
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:tusharashah
ID: 12487748
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
 

Author Comment

by:sstoos
ID: 12487827
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12487913
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
 

Author Comment

by:sstoos
ID: 12488001
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
 
LVL 18

Expert Comment

by:tusharashah
ID: 12488046
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question