473,288 Members | 2,350 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,288 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 3985
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.