473,411 Members | 1,991 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,411 software developers and data experts.

Postback and dynamically loadiing user controls. What am I doing wrong?

I still have not gotten this damn thing figured out and I'm asking for help
one last time before I give up on it. I have a user control that contains a
paged gridview control. The master page contains a menu control What I
want to happen is that, whenever a menu item is selected, the appropriate
user control will load. Simple enough? Well, not for me.

I finally got the gridview paging and postback issue resolved thanks to
http://scottonwriting.net/sowblog/posts/2129.aspx . But now I have another
problem. I need the master page to load different controls based on which
menu item is clicked. For example, my menu has "Item1" and "Item2". When
I click "Item1" the paged gridview user control loads. When I click "Item2"
another user control will load. However, I cannot make this work.

On the master page is the <asp:Menunamed "mnuTicketMan". Inside the
menuItemClick event handler, I have the following code:

mvTicketMan.ActiveViewIndex = Int32.Parse(e.Item.Value);
strDBView =
mvTicketMan.Views[Int32.Parse(e.Item.Value)].ID.ToString().Replace("vw",
"").Replace("_", " ");
ViewState["DBView"] = strDBView;

What I originally tried to do was load the controls in that event handler.
Something like:

if (strDBView == "Item1")
// load gridview control
// add gridview control to a placeholder
// bind data to gridview
if (strDBView == "Item2")
// load the item2 control
// add item2 control to a placeholder

Problem there was that the controls wouldn't work correctly because they
were only being loaded when the menu is clicked. If I clicked on a data
page of the gridview control, it would send a postback and not reload the
control----because the menu wasn't clicked.

So, I eventually got the paging working by loading the control on the master
page's Page_Load event handler. Something like this:

void Page_Load {
// load user gridview control
// add user gridview control to placeholder

if (!IsPostBack)
// load the menu items
// bind the gridview data
}

But you'll notice one thing above. I am loading that gridview user control
everytime. That's not what I want. No problem. I'll just create a global
string variable, assign its value in the menuItemClick event handler, and
then check it in the Page_Load event handler. Something like this:

//menuItemClick handler
mvTicketMan.ActiveViewIndex = Int32.Parse(e.Item.Value);
strDBView =
mvTicketMan.Views[Int32.Parse(e.Item.Value)].ID.ToString().Replace("vw",
"").Replace("_", " ");
ViewState["DBView"] = strDBView;
globalVar = strDBView;

// Page_Load handler
if (globalVar == "Item1")
// load user gridview control
// add user gridview control to placeholder
if (globalVar == "Item2")
// load another control
// add another control to placeholder

if (!IsPostBack)
// load the menu items
// bind the appropriate control to data

Nope. No prize for me. "globalVar" gets set when the menu is clicked but
it gets reset in the Page_Load handler. Basically, "globalVar" never ==
Item1 or Item2 when the page is loaded. I have tried placing the control
loading code in various places...like OnInit, OnPreRender, etc. "globalVar"
does keep its value inside the Init and PreRender but loses it in Load. I
have also tried using ViewState to store the value but the same thing
happens.

So, how can I make this work? I need globalVar to keep its value after it
gets set upon the menu item click. Or, if someone knows another way of
going about this, I'd appreciate that as well. I hope someone responds
because I spent 35 minutes typing this post! :) I will provide the actual
code if need be.

TIA
John



Aug 22 '06 #1
0 2194

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

Similar topics

2
by: Duwayne | last post by:
I am having lots of trouble with one of my user controls (ascx) not automatically loading postback data. An image on the aspx page starts the postback and the parent has no problem loading it's own...
10
by: Krista Lemieux | last post by:
I'm new to ASP.NET and I'm not use to the way things are handled with this technology. I've been told that when I have a control, I should only bind the data to it once, and not on each post back...
13
by: Chris Thunell | last post by:
I have created several grids dynamically and have added them to different HTML placeholders on a vb.net web form. The grids and controls within them come up and view beautifully when the web page...
5
by: PCH | last post by:
I have an c# asp.net (.net 1.1) web page, viewstate on. The problem I am having is on the button click postback to update. Heres the situation: I have an asp table that has 1 header row. ...
5
by: Psych971 | last post by:
Hi, I'm wondering how I can generate a postback using javascript on a page that does not have any controls with the auto-postback property set to true. I know I can just use the submit() function...
1
by: Christian Nunciato | last post by:
Hi there: I've checked the forums, but haven't found a situation addressing my specific problem. Here's the deal: I've got a Web Form containing two Panel controls. One displays search...
4
by: epigram | last post by:
I've got a page that has a Panel object that I am dynamically adding CheckBox controls to. The number of CheckBox controls and the name of each control is based on a database query. I would like...
1
by: Marcus | last post by:
I have a problem maybe one of you could help me with. I've created a data entry screen with lots of dynamically-created client-side controls. I create HTML texboxes client-side by assigning a...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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
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...

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.