在ASP.Net中部分更新后不加载JavaScript

时间:2012-12-07 05:52:09

标签: c# javascript asp.net updatepanel postback

我有一个问题,当一个updatepanel回发到服务器时,javascript没有加载到asp.net,问题是javascript代码不在updatepanel所在的同一页面,所以我可以把它放在pageLoad()函数中是这样的:

<script src="js/keyboard.js" type="text/javascript"></script>

我使用ASP.Net 4和c#,这是我的代码:

<link href="css/keyboard.css" rel="stylesheet" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div style="text-align: left; padding-right: 140px">
            <dx:aspxcombobox id="comboBoxLangauge" clientinstancename="comboboxLang"
                cssclass="combo" runat="server" width="140px" clientidmode="Static">
                <Items>
                    <dx:ListEditItem Text="English to Kurdish" Value="1" Selected="true" />
                    <dx:ListEditItem Text="Kurdish to English" Value="2" />
                </Items>
                <ClientSideEvents SelectedIndexChanged="IndexChanged" />            
            </dx:aspxcombobox>
        </div>
        <br />
        <br />
        <asp:Button ID="btnTranslate" runat="server" Text="Search" ClientIDMode="Static"
            CssClass="Search" OnClick="btnTranslate_Click" />
        <asp:TextBox ID="txtBoxWord" runat="server" ClientIDMode="Static"
            class="keyboardInput Search" Style="width: 260px; direction: ltr"></asp:TextBox>

        <asp:AutoCompleteExtender ID="autocom" ClientIDMode="Static" runat="server" CompletionSetCount="10"
            EnableCaching="true" MinimumPrefixLength="1" TargetControlID="txtBoxWord" ServicePath="~/translator/AutoComplete.asmx" ServiceMethod="GetCompletionList">
        </asp:AutoCompleteExtender>

        <asp:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server" TargetControlID="OutPanel"
            Corners="All" Radius="5" BorderColor="Silver">
        </asp:RoundedCornersExtender>
        <br />
        <br />
        <div id="OutPanel" runat="server" clientidmode="Static" style="width: 440px; height: 200px; overflow: auto; margin-left: auto; margin-right: auto; padding-top: 10px;" visible="false">
        </div>
    </ContentTemplate>
</asp:UpdatePanel>
<div id="OutPanel" runat="server" clientidmode="Static" style="width:440px;height:200px;overflow:auto;margin-left:auto;margin-right:auto;padding-top:10px;" visible="false">

</div>
        </ContentTemplate>
    </asp:UpdatePanel>

1 个答案:

答案 0 :(得分:0)

  

“问题是javascript代码不在updatepanel所在的同一页面中”

确保您的 JavaScript UpdatePanel页面上可用,以便正确加载。