473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

State not preserved in inner controls of ASCX control

Hi all,

In my page class, I'm loading a user control:

private void Page_Load(object sender, System.EventArgs e)
{
Control c = LoadControl("WebUserControl1.ascx");
Controls.AddAt(0, c);

}

Inside WebUserControl1.ascx I have a hyperlink whose NavigateUrl property is
set at runtime (e.g. in Page_Load). Here's the code form
WebUserControl1.ascx.cs

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
HyperLink1.NavigateUrl = "/SomePage";
}

The problem is that if my page has a control that causes postback (e.g.
Button), the next time the page loads, the hyperlink inside the user control
doesn't retain its NavigateUrl property. I'm wondering why this is
happening.

In my scenario, I can't drop the user control (ASCX) on the page, because
the page is a bare .cs class (base page) without ASPX.

Thanks,
-Oleg.
Nov 18 '05 #1
1 1577
Hi,

try such that don't use Controls.AddAt, but instead put a placeholder onto
the Page and add the user control to its Controls collection or optionally
use Controls[1].Controls.Add(c); (By default Form is at this index so this
is same as adding Control to Form's Controls collection)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"Oleg Ogurok" <ol**@ogurok.com.ihatespammers.ireallydo.co> wrote in message
news:10*************@corp.supernews.com...
Hi all,

In my page class, I'm loading a user control:

private void Page_Load(object sender, System.EventArgs e)
{
Control c = LoadControl("WebUserControl1.ascx");
Controls.AddAt(0, c);

}

Inside WebUserControl1.ascx I have a hyperlink whose NavigateUrl property is set at runtime (e.g. in Page_Load). Here's the code form
WebUserControl1.ascx.cs

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
HyperLink1.NavigateUrl = "/SomePage";
}

The problem is that if my page has a control that causes postback (e.g.
Button), the next time the page loads, the hyperlink inside the user control doesn't retain its NavigateUrl property. I'm wondering why this is
happening.

In my scenario, I can't drop the user control (ASCX) on the page, because
the page is a bare .cs class (base page) without ASPX.

Thanks,
-Oleg.

Nov 18 '05 #2

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

Similar topics

1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the...
1
by: Josh | last post by:
I am trying to move some of my more common controls into user controls. However, I seem to have problems maintaining state of databound controls that are contained within user controls. On...
5
by: Amelyan | last post by:
How can I get state of dynamically created controls (RadioButton, CheckBox, TextBox.Text) on post back when I click submit button? The only way I know is by traversing Response.Form enumberator;...
3
by: Neven Klofutar | last post by:
Hi, I recently read an article on MSDN about viewstate and postback. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/viewstate.asp The author states the following:...
2
by: Scott | last post by:
I'm using a master page (mp_TableMaint.aspx) with one Content area (ID: Content1). Content1 contains several usercontrols, which are hidden. The goal is to show the correct control based on the...
9
by: Alan Silver | last post by:
Hello, I have a user control which I am trying to load dynamically, but am running into problems. I think the problem is because I have two .ascx files that refer to the same .ascx.cs file. A...
4
by: tshad | last post by:
Is there a way for a User Control to access an object (such as label or textbox) on the .aspx page that calls it? For example: x.aspx ************************************** .... Sub...
8
by: mark.norgate | last post by:
I've asked this question before, but still haven't solved it, so am asking again. I am programmatically adding a user control to the page in response to a button click. The user control consists...
5
by: tshad | last post by:
I have a PageInit.ascx that I want to put in all my pages and have it execute only once during the "not IsPostback" section. I also need it to execute first before anything else. I have it set...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.