473,765 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic contols with LoadControl and ViewState

I have a "Tabbed" ASP.NET page. When a user clicks on a tab, i want
the corresponsing dynamic control to be loaded. This works great
except that the postbacks on that dynamically loaded control do not
work the first time they are attempted. Every subsequent attemp works
great. Here is what is happening

private void Page_Load(objec t sender, System.EventArg s e)
{
LoadContentCont rol();

if (!Page.IsPostBa ck)
{
BindTabs();
BindContent(); }
}

The LoadContentCont rol loads the correct control based on a variable
stored int the ViewState. If that variable is not initialized that
function will initialize it. Everything works fine and the correct
control loads. Now i have tabs on the page and by clicking on one of
the tabs, a different control should load.

private void TabControl_Sele ctedTabChanged( object sender, EventArgs e)
{
ViewState["ContentControl "] = TabControl.Tabs .SelectedTab;
LoadContentCont rol();
BindContent();
}

That works as well, however because the LoadContentCont rol is not in
the page load ie it happens after, any post back on the dynamically
loaded control will not work, untill the page is loaded again so that
the LoadContentCont rol in the page load gets fired. So what seems to
be happening is that the LoadContentCont rol needs to be in the page
load for the postback events need to be handled.

A fix to this would be when the new value for the
ViewState["ContentControl "] is assigned to it in the Tab changed
event, then the page re-initializes or reloads to itself. Then the new
"ContentControl " would be loaded in the first LoadContentCont rol and
everything would work.

Or if you have any other ideas it would be apreciated

Thanks

Mark
Nov 18 '05 #1
0 2839

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
483
by: Mark | last post by:
I have a "Tabbed" ASP.NET page. When a user clicks on a tab, i want the corresponsing dynamic control to be loaded. This works great except that the postbacks on that dynamically loaded control do not work the first time they are attempted. Every subsequent attemp works great. Here is what is happening private void Page_Load(object sender, System.EventArgs e) { LoadContentControl();
4
1567
by: John | last post by:
Hi all, I have posted this type of question quite a few times but to date, no-one has actually been able to provide me with a solution. I really need to understand how to do this properly. My situation: I have n user controls which, based on user input, interchange with a placeholder on a web form.
3
2270
by: Stu | last post by:
Hi, I am creating a control in a PlaceHolder like so: Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Dim ctrl As AcceptOrCancel = CType(Page.LoadControl("controls/AcceptOrCancel.ascx"), AcceptOrCancel) PlaceHolder1.Controls.Add(ctrl)
7
1935
by: John | last post by:
Hi all, I need finality on this once and for all please. I have a main page which contains a couple of placeholders and within these placeholders, depending on what the user presses, I load different user controls. This loading of user controls is done within the code-behind of the main page. The problem is that before loading a user control in place of another, I need to do a Controls.Add then a Controls.Remove so the viewstate is...
6
2745
by: John | last post by:
Hi all, I am using dynamic user controls within my web app and these controls are loaded into placeholders via the LoadControl method. My problem is this: I have usercontrolA loaded into a placholder and the user clicks on a specific control outside of the usercontrol and some Javascript is run where a hidden variable is changed to reflect another usercontrol (usercontrolB).
2
1645
by: mivhaelveloz | last post by:
I thought I had a good grip on viewstate handling, but am suprised by a small test: In my aspx file I have a PlaceHolder control and a button for posting back. Dynamically in Page_Load I create a TextBox, and add it as a control of PlaceHolder. I do this regardless of whether IsPostBack is true or not, to insure
1
2353
by: Gummy | last post by:
Hello, I am loading several user controls dynamically in OnInit() like this: ucListBoxSelections ucLocation = (ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");
4
51670
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox controls need to be dynamically loaded according to user input. This simple example can be further extended to dynamically load custom web user controls. Background Please familiarize yourself with the ASP.NET Page Life Cycle. It is crucial to...
0
2941
by: CMELLO | last post by:
I have am dynamically loading a web user control based on the click of a tab strip I load the default control for the first tab in the page load event after checking page is not postback. After that the controls are loaded/unloaded based on the SelectionChanged event for the tab strip and again in Page load because with a dynamic load viewstate has to be reloaded. I have a datalist in the user control and I am trying to create the...
0
1915
by: =?Utf-8?B?Y2luZHk=?= | last post by:
I have am dynamically loading a web user control based on the click of a tab strip I load the default control for the first tab in the page load event after checking page is not postback. After that the controls are loaded/unloaded based on the SelectionChanged event for the tab strip and again in Page load because with a dynamic load viewstate has to be reloaded. I have a datalist in the user control and I am trying to create the...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.