Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我可以从代码隐藏更改按钮单击时的Jquery ui活动选项卡吗?_Javascript_Jquery_Asp.net_Jquery Ui Tabs - Fatal编程技术网

Javascript 我可以从代码隐藏更改按钮单击时的Jquery ui活动选项卡吗?

Javascript 我可以从代码隐藏更改按钮单击时的Jquery ui活动选项卡吗?,javascript,jquery,asp.net,jquery-ui-tabs,Javascript,Jquery,Asp.net,Jquery Ui Tabs,我已经实现了Jquery选项卡,就像我想要的那样。 但我还想更改按钮上的活动选项卡,单击“代码隐藏”并说“保存” 当我的记录成功保存时 如何在服务器上执行此操作单击以下内容: onclick='$("#tabs").tabs("option", "active", 2);' 示例HTML代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></t

我已经实现了Jquery选项卡,就像我想要的那样。 但我还想更改按钮上的活动选项卡,单击“代码隐藏”并说“保存” 当我的记录成功保存时

如何在服务器上执行此操作单击以下内容:

onclick='$("#tabs").tabs("option", "active", 2);'
示例HTML代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
  <script src="http://code.jquery.com/jquery-1.10.0.js" type="text/javascript"></script>
    <link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />

    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {

            $('#tabs').tabs({
                activate: function () {
                    var newIdx = $('#tabs').tabs('option', 'active');
                    $('#<%=hidLastTab.ClientID%>').val(newIdx);

                }, heightStyle: "auto",
                active: previouslySelectedTab,
                show: { effect: "fadeIn", duration: 1000 }
            });

        });
 </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="width:900px; margin:0 auto">
    <div id="tabs" style="margin:0 auto;  margin-bottom:2px;">
    <ul>
        <li><a href="#tabs-1">STATE TRACKING</a></li>
        <li><a href="#tabs-2">ICONS</a></li>
        <li><a href="#tabs-3">Effects</a></li>

    </ul>
    <div id="tabs-1">
    <strong>STATE TRACKING</strong>
        <p>This is first tab.</p>
    </div>
     <div id="tabs-2">
     <strong>ICONS</strong><p>
     Note : Remains on same tab after postback if I check/uncheck checkbox.
    </p>
    <asp:CheckBox ID="CheckBox1" runat="server"  AutoPostBack="true" Text="Hi"/>
    <br />
    <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
    </div>

      <div id="tabs-3">
    <strong> The jQuery UI effects</strong><p>
    This is third tab.
    </p>
    </div>

  </div>
  <asp:HiddenField ID="hidLastTab" Value="0" runat="server" />
  </div>

    </form>
</body>
</html>
我的示例代码隐藏:

protected void Page_Load(object sender, EventArgs e)
{
    String hiddenFieldValue = hidLastTab.Value;
    StringBuilder js = new StringBuilder();
    js.Append("<script type='text/javascript'>");
    js.Append("var previouslySelectedTab = ");
    js.Append(hiddenFieldValue);
    js.Append(";</script>");
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "acttab", js.ToString());
}

protected void btnSave_Click(object sender, EventArgs e)
{
    // Code goes here for Insert/Update on btnSave_Click()
    // After Insert/Update successfully, I have to select next tab (i.e. 3rd tab)
}

您只需运行在客户端使用的相同脚本,即从服务器端注入脚本

要做到这一点,只需使用。这将在页面完全加载到客户端后执行注入的脚本

如果您使用的是最新版本的框架,请使用

正如您在链接的引用页面中所看到的,它非常容易使用:只需调用作为字符串参数传递脚本的方法,它就会在客户端执行

请注意,有些重载允许自动引入标记,有些重载则需要键入脚本标记

例如,如果您在服务器端使用此代码,警报将在客户端执行,您将看到Hello World!浏览器上的对话框:

string script = "<script type=text/javascript> alert('Hello World!'); <script>");
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
要使其适合您的CA,只需将“script”var值设置为要在客户端运行的tabs脚本,即:

string script = "<script type=text/javascript>$('#tabs').tabs('option', 'active', 2);</script>";
请注意,可以在javaScript代码中使用单引号,以便更容易地将它们包含在服务器端字符串中


当然,您必须将此代码包含在您的按钮点击处理程序btnSave_Click…

请进一步解释,并显示一些示例代码。是否要在服务器端事件上设置活动选项卡?为什么不在客户端?我已经给出了示例代码示例,请通过:是的,我想在服务器端事件,因为我必须检查用户是否保存了记录。如果是,那么它应该自动选择下一个选项卡&我已经在本文中提到了它。你能给我一个示例,我如何存档它?再解释一下。嗨,佐塔贝。我已经编辑了我的问题,这样你就可以清楚地理解我想要什么。
string script = "<script type=text/javascript>$('#tabs').tabs('option', 'active', 2);</script>";