当AutoPostBack = true时,阻止在AJAX TabContainer上重新加载页面?

时间:2013-04-12 19:27:50

标签: c# asp.net .net tabcontainer

这可能吗?我有一个AJAX TabContainer,容器中有3个标签。在选项卡#2上,我有一个复选框,选中后会启用一个文本框。取消选中该复选框后,应禁用该文本框。

我的ASP代码中有这个代码:

    <AJAXControls:TabContainer runat="server" ID="tabContainer" Height="373" Width="900" > 
        <AJAXControls:TabPanel ID="firstTab" HeaderText="First Tab" runat="server"> 
            <ContentTemplate> 
                <asp:Label ID="Label1" runat="server">You are in the First tab.</asp:Label> 
            </ContentTemplate> 
        </AJAXControls:TabPanel> 
        <AJAXControls:TabPanel ID="secondTab" HeaderText="Second Tab" runat="server"> 
            <ContentTemplate> 
                <div>
                <asp:Panel ID="Panel1" runat="server" Height="70px" style="margin-left: 19px" 
                    Width="860px" BorderStyle="Groove" BorderWidth="2px">
                        <table>
                            <tr>
                                <td width="170">Review Validated:</td>
                                <td width="50"><asp:CheckBox ID="chkRevVal" runat="server" Text=" " oncheckedchanged="chkRevVal_CheckedChanged" AutoPostBack="true" /></td>
                                <td width="40"></td>
                                <td width="170">Validation Comments:</td>
                                <td width="380" rowspan = "4"><asp:textbox id="txtValComm" runat="server" textmode="multiline" rows="4" Width="380px"></asp:textbox></td>
                            </tr>
                            <tr></tr>
                            <tr></tr>
                            <tr></tr>
                        </table>
                </asp:Panel>             
            </ContentTemplate> 
        </AJAXControls:TabPanel> 
    </AJAXControls:TabContainer>

我在代码隐藏中得到了这个:

    protected void chkRevVal_CheckedChanged(object sender, EventArgs e)
    {
        if (chkRevVal.Checked == true)
        {

            this.txtValComm.Enabled = true;
            this.txtValComm.Focus();

        }
    }

问题是,当我选中此框时,TabContainer每次都会返回到#1选项卡。在我选中复选框后,有没有办法将它保留在标签#2上?

1 个答案:

答案 0 :(得分:2)

只需将Panel1控件放入带有UpdateMode="Conditional"的UpdatePanel即可。顺便说一下,重写chkRevVal_CheckedChanged

this.txtValComm.Enabled = chkRevVal.Checked;
if (txtValComm.Enabled) 
    txtValComm.Focus();