views:

18

answers:

1

I need to display a control consistently across a set of pages. So I'm using a MasterPage to do that in ASP.NET/C#. However I also need to programmatically access this control, mostly provide options to view/hide depending on whether the controls checkbox is clicked.

Here is the Source for the MasterPage

<div id="verifyInitial" runat="server">
    <asp:CheckBox ID="chkInitialVerify" runat="server" 
    oncheckedchanged="chkInitialVerify_CheckedChanged" />
    I agree that my initial data is correct.
</div>

<div id="verifyContinuous" runat="server">
    <asp:CheckBox ID="chkContinuousVerify" runat="server" 
    oncheckedchanged="chkContinuousVerify_CheckedChanged" />
    I agree that my continuous data is correct
</div>

Now in the code behind I want to perform the following operations. Basically if a person clicks on the checkbox for the initial div box, then the initial box disappears and the continous box shows up. However it seems that the code behind for the MasterPage does not activate whenver I click on the checkbox. Is that just the way MasterPages are designed? I always thought you could do add some sort of control functionality beyond utilizing the Page Load on the Master Page.

protected void chkInitialVerify_CheckedChanged(object sender, EventArgs e)
{
    verifyContinuous.Visible = true;
    verifyInitial.Visible = false;
}


protected void chkContinuousVerify_CheckedChanged(object sender, EventArgs e)
{
    verifyContinuous.Visible = false;
}
+1  A: 

If you're expecting the two controls to trigger a change for that page immediately then you'll need to set the AutoPostBack property to true for both of them:

<div id="verifyInitial" runat="server">
    <asp:CheckBox ID="chkInitialVerify" runat="server"  oncheckedchanged="chkInitialVerify_CheckedChanged" AutoPostBack="true" />
    I agree that my initial data is correct.
</div>

<div id="verifyContinuous" runat="server">
    <asp:CheckBox ID="chkContinuousVerify" runat="server" oncheckedchanged="chkContinuousVerify_CheckedChanged" AutoPostBack="true" />
    I agree that my continuous data is correct
</div>

Otherwise, you need an <asp:button /> or some other control on the page to trigger a postback and cause your event handlers to run. The button, or other control, can either be on your masterpage or on your content page, the choice is entirely yours.

Rob
oh wow, I knew I was missing something that was so obvious in retrospect. Thanks!
firedrawndagger
Not a problem, glad I could help =)
Rob