开发者

Problem with ajax tabcontainer

i use from ajax tabcontainer .and i want to when value of hiddenfield is not 1(value of hiddenfield change when i click in gridview,i dont have problem with set value for hiddenfield) and user click in email tab it alerts and stays in first tab.but in my code it alert and changes tab.i want to stay in cuurent tab. i write this code but it dosent work. please help me.

 <%@ Page Language="C#" %>


     <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>                
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org   


<script type="text/javascript">
   function SetActiveTab() {
   var hfd = $get('<%=HiddenField1.ClientID%>');
   if (hfd.value != "1") {
       alert("hitttttttt");
       var ctrl = $find('TabContainer1');
       ctrl.set_activeTab(ctrl.get_tabs()[0]);


   }

}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Ajax Control - Tabs </title>
 </head>
<body>
<form id="form1" runat="server">
         <b>Tabs Demonstration</b> <br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
         <asp:HiddenField ID="HiddenField1" runat="server" />
    <br />
    <asp:TabContainer runat="server" ID="TabContainer1" Height="138px"  ActiveTabIndex="0"
        Width="402px">
        <asp:TabPanel runat="server" ID="Panel1" HeaderText="Address" >
            <ContentTemplate>
                <asp:UpdatePanel ID="updatePanel1" runat="server">
                    <ContentTemplate>
                        <table>
                            <tr><td>First Name:</td><td><asp:TextBox ID="txtName" runat="server" /></td></tr>
 开发者_Go百科                           <tr><td>Address:</td><td><asp:TextBox ID="txtAddress" runat="server" /></td></tr>
                        </table>
                   </ContentTemplate>
                </asp:UpdatePanel>
            </ContentTemplate>
        </asp:TabPanel>

        <asp:TabPanel runat="server" ID="Panel3" HeaderText="Email" OnClientClick="SetActiveTab" >
            <ContentTemplate>
                Email: <asp:TextBox ID="txtEmail" runat="server" />

            </ContentTemplate>
        </asp:TabPanel>

        <asp:TabPanel runat="server" ID="Panel2"  HeaderText="Login Details" >
            <ContentTemplate>
             <table>
           <tr> <td>User Name:</td><td><asp:TextBox ID="txtUser" runat="server" /></td></tr>
           <tr> <td>Password:</td><td><asp:TextBox ID="txtPass" runat="server" /></td></tr>
            </ContentTemplate>
        </asp:TabPanel>

    </asp:TabContainer>


</form>


The one solution I found is to remove OnClientClick handler and use the javascript below:

 function pageLoad() {
    var tabContainer = $find('<%= TabContainer1.ClientID %>');
    var hfd = $get('<%= HiddenField1.ClientID %>');

    var oldSetActiveTab = Function.createDelegate(tabContainer, tabContainer.set_activeTab);

    tabContainer.set_activeTab = function (value) {
        if (value.get_id() == '<%= Panel3.ClientID %>' && hfd.value != "-1") {
            alert("oops");
        }
        else {
            oldSetActiveTab(value);
        }
    };
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜