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

Discussion in 'ASP .Net' started by Managed Code, Jul 27, 2006.

  1. Managed Code

    Managed Code Guest

    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_Init"));
    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>
     
    Managed Code, Jul 27, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug McCann
    Replies:
    1
    Views:
    1,108
    William Brogden
    Aug 5, 2004
  2. Sam
    Replies:
    1
    Views:
    802
  3. Evan M.
    Replies:
    1
    Views:
    1,231
    Evan M.
    Apr 18, 2007
  4. Replies:
    1
    Views:
    539
    Kuldeep
    Aug 31, 2007
  5. SerpentKiss2010
    Replies:
    0
    Views:
    2,534
    SerpentKiss2010
    Apr 6, 2011
Loading...

Share This Page