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

Postback,Master page,User control problem

Hello .Net Gurus. This is my first post here so I apologize in advance
if I have not provided the right information. I hope someone has seen
this problem before and can tell me what I am doing wrong. I have
simplified the problem with the following example:

Using asp.net 2.0, I have a Master page template used on default.aspx.
From within the Content tags on that page I placed a Datalist. It is

iterating a User control "Inner" with one property, Name. The user
control has a checkbox with OnChanged event firing a postback.

The problem is on postback to default.aspx, I need to know the state of
the Checkbox that was clicked on in the "Inner" user control. Alas,
the value is always FALSE. Only when the User control's OnChanged
event executes, do I see the new value.

When I do this without a Master page, it works as expected, and I can
see the new value of the Checkbox at the Page_Load of the default.aspx.
Any ideas what I am doing wrong here? (Thanks)

The code below is from default.aspx

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default"
MasterPageFile="~/templates/eDonations.master" %>

<%@ Register Src="inner.ascx" TagName="inner" TagPrefix="uc2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<uc2:inner id="Inner1" runat="server" Name=<%#
Container.DataItem %> >
</uc2:inner>
</ItemTemplate>
</asp:DataList>

</ASP:Content>
---------------------------------------
And here is the Code behind:

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList list = new ArrayList();
list.Add("1");
list.Add("2");

DataList1.DataSource = list;
DataList1.DataBind();
}
else
{
inner _inItem = new inner();
int ItemIndex = 0;
foreach (DataListItem _item in DataList1.Items)
{
++ItemIndex;
_inItem = (inner)_item.FindControl("inner1");
string hello = _inItem.Name;
CheckBox chk =
(CheckBox)_inItem.FindControl("Checkbox1");
if (chk.Checked)
{
//Do something
}
}
}
}
}

May 18 '06 #1
1 3996
Some tips...

// After the @Page directive put this into your file...
<%@ MasterType VirtualPath="~/MasterPage.master" %>

Enable trace for the page in the @Page directive. Load the page and observe
the hierarchical location of the Checkbox you want to find. When referencing
controls in a MasterPage we have to use the entire hierarchy with the
FindControl method.

It gets a bit tricky. Search the web for referencing controls in a
MasterPage.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

<yo*****@gmail.com> wrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
Hello .Net Gurus. This is my first post here so I apologize in advance
if I have not provided the right information. I hope someone has seen
this problem before and can tell me what I am doing wrong. I have
simplified the problem with the following example:

Using asp.net 2.0, I have a Master page template used on default.aspx.
From within the Content tags on that page I placed a Datalist. It is

iterating a User control "Inner" with one property, Name. The user
control has a checkbox with OnChanged event firing a postback.

The problem is on postback to default.aspx, I need to know the state of
the Checkbox that was clicked on in the "Inner" user control. Alas,
the value is always FALSE. Only when the User control's OnChanged
event executes, do I see the new value.

When I do this without a Master page, it works as expected, and I can
see the new value of the Checkbox at the Page_Load of the default.aspx.
Any ideas what I am doing wrong here? (Thanks)

The code below is from default.aspx

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default"
MasterPageFile="~/templates/eDonations.master" %>

<%@ Register Src="inner.ascx" TagName="inner" TagPrefix="uc2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<uc2:inner id="Inner1" runat="server" Name=<%#
Container.DataItem %> >
</uc2:inner>
</ItemTemplate>
</asp:DataList>

</ASP:Content>
---------------------------------------
And here is the Code behind:

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList list = new ArrayList();
list.Add("1");
list.Add("2");

DataList1.DataSource = list;
DataList1.DataBind();
}
else
{
inner _inItem = new inner();
int ItemIndex = 0;
foreach (DataListItem _item in DataList1.Items)
{
++ItemIndex;
_inItem = (inner)_item.FindControl("inner1");
string hello = _inItem.Name;
CheckBox chk =
(CheckBox)_inItem.FindControl("Checkbox1");
if (chk.Checked)
{
//Do something
}
}
}
}
}

May 19 '06 #2

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

Similar topics

5
by: Michael Herman \(Parallelspace\) | last post by:
1. What are some compelling solutions for using Master/Content pages with Web Pages? 2. If a content area has a web part zone with web parts, what is the user experience like when "editting" the...
0
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and...
0
by: John Smith | last post by:
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...
2
by: TheAmes | last post by:
Hi I have a asp.net site in VB.NET and VWD 2005 Express. in the master page i have a Label. from a content page i change the value of this label like so: dim X as label =...
5
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I have a user control (not ascx though - rendered when the page loads), actually it's a basket control on a master page. This master page includes a wizard page too, however when...
6
by: anthonykallay | last post by:
Hi there, I dont this this a bug but i cant get my head around it.. I have a master page that has a login control on it, to log in i press the button and the page posts back, however on the page...
2
by: =?Utf-8?B?SlA=?= | last post by:
Hi all. I'm having a problem with a postback issue and I think it's cache related. Here's my setup: I have a web site that has a signup section. This has simple things like name, age, birth...
0
by: db007 | last post by:
I have a problem at the moment with a web project. I have two Panels within an UpdatePanel on an aspx page (using Masterpages). I'm using ASP.Net 2.0 with an AJAX enabled website. The two...
2
CroCrew
by: CroCrew | last post by:
I know that I should post my question in the asp.net forum but I did not want just anyone to answer my question. I want just the “Pros” answers. First off; I don’t want to use master pages. I hate...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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,...
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...

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.