每次刷新内部后,在更新面板中调用脚本或函数

时间:2013-08-09 11:47:21

标签: c# asp.net

我的标题部分是

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>SimpleAdmin</title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>   
<script type="text/javascript">
    $(function () {
        $(".box .h_title").not(this).next("ul").hide("normal");
        $(".box .h_title").not(this).next("#home").show("normal");
        $(".box").children(".h_title").click(function () {$(this).next("ul").slideToggle(); });
    });
</script>   
</head>

我的身体部位

<body>
<form id="form" runat="server">  

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>    

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>        
<asp:DataList ID="dtlheader" runat="server" Width="189px">
        <ItemTemplate>
         <table cellpadding="0" cellspacing="0" width="100%" onmouseover="this.style.background='#683372'" onmouseout="this.style.background='#3e3d3b'"  style="background-color: #3e3d3b;">
         <tr>
         <td>
            <div class="box">
              <div class="h_title" style="color: #FFFFFF"><%# Eval("header") %></div>
                <ul>
                    <asp:DataList ID="dtlsubtitle" runat="server">
                        <ItemTemplate>
                            <table cellpadding="0" cellspacing="0" width="100%" onmouseover="this.style.background='#ececec'"
                                                    onmouseout="this.style.background='#ececec'"  style="background-color: #ececec;"><tr><td>
                               <asp:LinkButton ID="lnk" runat="server" onclick="lnk_Click"><%# Eval("subtitle") %></asp:LinkButton>
                                </td></tr></table>
                        </ItemTemplate>
                    </asp:DataList>
                </ul>
            </div>
            </td>
            </tr>
            </table>
        </ItemTemplate>
    </asp:DataList>  
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>

这是 switchmenu 的脚本 在第1页加载它是正常工作,但在做链接按钮点击里面, 比以后脚本不再工作。

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,这应该解决它:

<强>的Javascript

$(function () {        
    $(".box .h_title").not(this).next("ul").hide("normal");
    $(".box .h_title").not(this).next("#home").show("normal");
});

function lbClicked(obj) {
    $(obj).next("ul").slideToggle(); 
}

<强> ASP.NET

<asp:LinkButton ID="lnk" runat="server" onclick="lnk_Click" onclientclick="lbClicked(this)"><%# Eval("subtitle") %></asp:LinkButton>

<强> C#

protected void Page_Load(object sender, EventArgs e)
{
    // You don't need the line below, which is wrong anyway
    //ScriptManager.RegisterStartupScript(this, this.GetType(), "javascript", "function();", true);

}
  protected void lnk_Click(object sender, EventArgs e)
{
    // You don't need the line below, which is wrong anyway 
    //ScriptManager.RegisterStartupScript(this, this.GetType(), "javascript", "function();", true);
}