By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

content page subscriber to master page event doesn't update on 2nd postback

P: n/a
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 sets
a connection string to the database. The content page has a
simple gridview that should show records from the selected
database. Initial content page displays data from correct place.
first change of dropdownlist correctly updates content page
gridview. any drop down list changes after that are ineffective.
I've attempted session state index saving in conjunction with
content page and master page load events during postback and not
postback. I've slimmed down to the basics to show my problem.
Here is the flow....

CP = Content Page
MP = Master Page

This is the first page load. The first four things listed here
happen every page.

CP::CP Constructor to content page
MP::MP Constructor to Master page
MP::MP_Init Master page init
CP::Page_Init Page INIT
(subscribe to select change event)

CP::Page_Load:NOTPostBack Initial call to page_load
CP::GridView1_DataBound bind it up and display records from
default db. this works to correct
database.

----------------------------------------------------------------------------------------------------
CP::Page_Load:PostBack the first postback
MP::CSDDL_SIC FIRED master page drop down changed by user
MP::Fire Index(1) master fires new index to content page
CP::Catch Index(1) content page catches
CP::GridView1_DataBound bind it up and display records from new
database. this works perfectly
----------------------------------------------------------------------------------------------------
CP::Page_Load:PostBack another post back to content page
MP::CSDDL_SIC FIRED master page drop down changed by user
MP::Fire Index(0) master fires new index to content page
CP::Catch Index(0) content page catches
*****Lack of LLT::GridView1_DataBound here and on all subsequent
dropdownlist changes*****

MASTER CODEBEHIND
public partial class MyMasterPage : MasterBase
{
public event ConnStrChangedEventHandler ConnStrChanged;

public MyMasterPage() {
Debug.WriteLine(String.Format("MP::MP"));
this.Init += new System.EventHandler(this.MyMasterPage_Init);
}

protected void CSDDL_SIC(object sender, EventArgs e) {
Debug.WriteLine(String.Format("MP::CSDDL_SIC FIRED"));
ConnStrChangedEventArgs CSCEA;
CSCEA = new ConnStrChangedEventArgs(CSDDL.SelectedIndex);
if (ConnStrChanged != null) {
Debug.WriteLine(
String.Format("MP::Fire Index({0})", CSCEA.Index));
ConnStrChanged(this, CSCEA);
}
}

private void MyMasterPage_Init(object sender, EventArgs e) {
Debug.WriteLine(String.Format("MP::MyMasterPage_In it"));
CSDDL.Items.Add(new ListItem("DEV1"));
CSDDL.Items.Add(new ListItem("ATLQA"));
CSDDL.SelectedIndex = 0;
}
}

CP(CONTENT) CODEBEHIND
public partial class CP : System.Web.UI.Page {
public CP() {
Debug.WriteLine("CP::CP");
this.Load += new System.EventHandler(Page_Load);
this.Init += new System.EventHandler(Page_Init);
}

protected void Page_Init(object sender, EventArgs e) {
Debug.WriteLine("CP::Page_Init");
Master.ConnStrChanged += new
ConnStrChangedEventHandler(Master_ConnStrChanged);
}

void Master_ConnStrChanged(object sender, ConnStrChangedEventArgs e)
{
Debug.WriteLine(String.Format("CP::Catch Index({0})", e.Index));
SqlDataSource1.ConnectionString =
ConfigurationManager.ConnectionStrings[e.Index + 1].ConnectionString;
}

protected void Page_Load(object sender, EventArgs e) {
if (IsPostBack) {
Debug.WriteLine("CP::Page_Load:PostBack");
}
else {
Debug.WriteLine("CP::Page_Load:NOTPostBack");
}
}

ENTIRE LISTING OF MASTERPAGE.MASTER FILE
<%@ Master Language="C#"
AutoEventWireup="true"
CodeFile="MasterPage.master.cs"
Inherits="MyMasterPage" %>
<html>
<head runat="server"><title>W</title></head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:contentplaceholder id="CP" runat="server" />
</td>
</tr>
<tr>
<td>Database</td>
<td>
<asp:DropDownList
ID="CSDDL"
runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="CSDDL_SIC" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

LLT.ASPX (Content Page) stripped
<%@ Page Language="C#"
MasterPageFile="~/MasterPage.master"
AutoEventWireup="true"
CodeFile="WF_STATUS.aspx.cs"
Inherits="LLT"
EnableSessionState="True" %>
<%@ MasterType TypeName="MyMasterPage" %>
<asp:Content ID="Content1"
ContentPlaceHolderID="CP"
Runat="Server">
<div>
<asp:GridView
ID="GridView1"
runat="server"
DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound"
OnDataBound="GridView1_DataBound" />
<asp:SqlDataSource />
</div>
</asp:Content>

Jul 27 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.