473,574 Members | 3,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

custom control viewstate problem - please help so i can sleep

Hi, can someone please help me with my custom control viewstate problem....I
haven't slept for hours trying to get this fixed.

I am making two custom controls which will be included on a single page. For
now, I will call them box1 and box2. Each box has a panel and will display a
list of link buttons on the panel.
When the page loads for the first time, box1 will call the database and
create a list of linkbuttons and each link button has a CommandArgument
which represents an ID that will be passed on to box2.

I defined a custom event in box1 which will be fired when a linkbutton is
clicked. In my default.aspx, I capture that event and extract the
commandargument , and then set the ID property of box2 and load another set
of linkbuttons in box2 for that id.

it kinda works for the first half right now, i can load box2's linkbuttons
for the correct id on page postback, however, my problem is that if a
linkbutton in box2 is clicked, when the page reloads, i lose all the
linkbuttons in box2.

I know I need to recreate all the controls in box2 on every postback. But I
just can't get it to work.

My questions are:

First, Is it a good or bad idea to use custom event + property setter to
pass data between controls and trigger the loading of the second box?

I have tried to override the OnInit, CreateChildCont rols(), OnPrerender(),
etc in box2, to check if the ID is in the viewstate from box1, if it is
there, I call the LoadInfoObject( ) method directly. But it didn't work,
viewstate was always null.
so the second question is how and when should I store the ID from box1 in
the viewstate? in which method in box2 can i access that viewstate?

I have attached my code below.

Please enlighten me.

Walter
(BOX1)
InfoChannelsLis tViewer.cs

public event MyEventHandler SelectedInfoCha nnelChanged;

public InfoChannelsLis tViewer() {} //ctor

protected override void CreateChildCont rols()
{
Panel infoChannelsPan el = new Panel();
infoChannelsPan el.EnableViewSt ate = true;
Controls.Add(in foChannelsPanel );

foreach (InfoChannel channel in Db.GetInfoChann els()
{
LinkButton lbtnInfoChannel = new LinkButton();
lbtnInfoChannel .CommandName = "SelectInfoChan nel";
lbtnInfoChannel .CommandArgumen t = channel.ID.ToSt ring();
lbtnInfoChannel .Text = channel.Name;
lbtnInfoChannel .Click += new
EventHandler(lb tnInfoChannel_C lick);

infoChannelsPan el.Controls.Add (lbtnInfoChanne l);
}
}

void lbtnInfoChannel _Click(object sender, EventArgs e)
{
if (sender is LinkButton)
{
LinkButton btn = sender as LinkButton;
if (btn.CommandNam e == "SelectInfoChan nel")
{
//store channel id in viewstate
ViewState["InfoChanne lId"] = btn.CommandArgu ment;

//raise Channel Changed event
MyEventArgs arg = new MyEventArgs
(MyEventType.In foChannelEvent, Convert.ToInt32 (btn.CommandArg ument));
SelectedInfoCha nnelChanged(thi s, arg);
}
}
}

(Box2)
InfoObjectListV iewer.cs

private int _infoChannelId;

public int InfoChannelId
{
get { return _infoChannelId; }
set
{
_infoChannelId = value;
if (_infoChannelId 0)
{
LoadInfoObject( _infoChannelId) ;
}
}
}

private void LoadInfoObject( int infoChannelId)
{
Panel panel2 = new Panel();
this.Controls.A dd(panel2);

foreach (InfoObject obj in Db.GetInfoObjec ts(infoChannelI d)
{
LinkButton infoObjectButto n = new LinkButton();
panel2.Controls .Add(infoObject Button );

infoObjectButto n.CommandName = "SelectInfoObje ct";
infoObjectButto n.CommandArgume nt = obj.ID.ToString ();
infoObjectButto n.Text = obj.Title;
infoObjectButto n.Click += new
EventHandler(in foObjectButtonS endID_Click);
}
}

void infoObjectButto nSendID_Click(o bject sender, EventArgs e)
{
if (sender is LinkButton)
{
LinkButton btn = sender as LinkButton;
if (btn.CommandNam e == "SelectInfoObje ct")
{
this.Page.Sessi on["InfoObject ID"] = btn.CommandArgu ment;
//TODO: further update
}
}
}

Oct 11 '06 #1
0 1657

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

Similar topics

0
1025
by: Emrah Gozcu | last post by:
I have a custom control tabstrib and it loads another custom control when clicked a tab. Tabstrib event fires well but the other custom control which is dynamicly loaded after clicking a tab, does not fire its event! This is a common issue i beleive. I use the code in OnPreRender to find get the event but it is ugly! if(Page.IsPostBack...
2
3894
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow javascript checks for things like valid e-mail addresses or phone numbers (without having to add a separate control for validation). One idea I...
2
3181
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/creatingcustomcolumns.asp The problem I am having is that the data in the custom datagridcolumn is not saved to viewstate and after...
3
1859
by: Chris Newby | last post by:
I have a very simple custom control that derives from WebControls.Panel and implements INamingContainer. It appear that controls created as children of my custom control are having ViewState problems. For example, suppose I create a ListBox control as a child of my custom control, attach a SelectedIndexChanged event handler to it, and bind...
7
2979
by: Shimon Sim | last post by:
I have a custom composite control I have following property
0
1761
by: spacehopper_man | last post by:
hi - I am writing a "tab" control. - but it's losing the viewstate of the content pane when I switch between tabs. can anyone shed any light on why I'm losing ViewState based on my simple example below? - if I put the tabs at the top of the screen viewstate is lost -
1
2237
by: Pavan | last post by:
Hi All, I have created a custom DataList web custom control, which populates data from a dataset. This dataset is available at runtime and exposed as property by my custom control. During preRender event of custom control, i populate Column Headers, Item Data from the DataSet using CustomTemplate class for my inner DataList
0
1541
by: Pavan | last post by:
My name is Pavan and I am a software engineer working on ASP .Net web development. Currently I am using .Net 2.0 Professional Edition to develop my web pages. I have a problem
3
1258
by: Chu | last post by:
Hello All- I've got a Custom Web Control that with a public class that that sets a private variable inside the class. I plop the custom control onto my page and off I go. From my main page, I call the customPage.loadPage(10) and pass in a value of 10. The loadPage method sets var1 = 10 as expected; however, when the customPage's button is...
0
7805
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...
0
8052
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. ...
0
8234
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...
1
7815
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...
0
8098
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6452
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...
1
5620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3740
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3749
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.