asp.net - 在更新面板中调用脚本或css样式

标签 asp.net css

我在页面上使用了一个脚本,因此下拉菜单、复选框和文本框的样式发生了变化,但是如果我将下拉菜单或任何其他工具放在更新面板中,则不会调用该工具的脚本。


这是我的html部分

<head runat="server">
<title>script not working</title>      
<script src="js/jquery/jquery-1.4.1.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="jqtransformplugin/jqtransform.css" type="text/css" media="all" />
<script type="text/javascript" src="jqtransformplugin/jquery.jqtransform.js"></script>

<script language="javascript">
    $(function() {
        $('form').jqTransform({ imgPath: 'jqtransformplugin/img/' });
    });
</script>
</head>
<body>
<form id="form1" runat="server">    
    <table cellpadding="0" cellspacing="0">
        <tr>
            <td>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>                 
            </td>               
        </tr>
        <tr>
            <td>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
                            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                            <asp:ListItem>1</asp:ListItem>
                            <asp:ListItem>2</asp:ListItem>
                            <asp:ListItem>3</asp:ListItem>
                            <asp:ListItem>4</asp:ListItem>
                            <asp:ListItem>5</asp:ListItem>
                            <asp:ListItem></asp:ListItem>
                        </asp:DropDownList>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>               
        </tr>            
        <tr>               
            <td>
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>
                        <asp:DropDownList ID="ddtrial" runat="server" AutoPostBack="True" 
                            onselectedindexchanged="ddtrial_SelectedIndexChanged">
                            <asp:ListItem>1</asp:ListItem>
                            <asp:ListItem>2</asp:ListItem>
                            <asp:ListItem>3</asp:ListItem>
                            <asp:ListItem>4</asp:ListItem>
                            <asp:ListItem>5</asp:ListItem>
                            <asp:ListItem></asp:ListItem>
                        </asp:DropDownList>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>           
    </table>   
</form>
</body>

我遇到了以下问题:

当页面获取加载脚本时,会显示下拉列表,但只要其中一个下拉列表被选择更改,两个下拉脚本都会被删除。

最佳答案

确保处理程序后面的 onselectedindexchanged="DropDownList1_SelectedIndexChanged"代码引用了当前对象,即更新面板

例如:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this, this.GetType(), "abc", "JavascriptFunctionName();", true);
}

关于asp.net - 在更新面板中调用脚本或css样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17124349/

相关文章:

javascript - 如何使用 jquery 一个一个地隐藏元素然后一个一个地显示它们?

css - "a"元素的相同高度和垂直对齐

c# - 复制的 NameValueCollection 的 ToString() 未输出所需的结果

asp.net - 如何在 asp.net 中卡住 gridview 列标题?

asp.net - SQL Server session 状态、网络场和 IIS 配置

php - 使用链接自动填充另一个表单,可能吗?

javascript - Jquery如何在不指定列表中事件的情况下触发函数

.net - @font-face 在本地主机上工作正常,但在 AppHarbor 中不行

html - 如何在可变宽度的较小 div 内水平居中较大的可变宽度 div

c# - Asp.net 按钮对象 - runat 服务器问题