473,799 Members | 3,065 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 1667

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

Similar topics

0
1032
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 && Page.Request.Form != null)
2
3921
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 did some work on was having the control implement the IValidator interface and basically recreating...
2
3201
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 postback, the column does not contain data.
3
1869
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 its data in the Page_Load event handler only if the current request is not a post back. I load the...
7
3020
by: Shimon Sim | last post by:
I have a custom composite control I have following property
0
1769
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
2243
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
1550
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
1266
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 clicked and the page is posted back, var1 is set back to it's initial state of -1.
0
9688
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
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
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...
1
7571
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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
5467
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.