javascript - 我想在 asp updatepanel 中使用这个 javascript 函数,详细信息如下

标签 javascript c# asp.net webforms

Here is the script that I am using for opening a new tab and it's working without using an update panel:

<script type="text/javascript">
    function openInNewTab() {
        window.document.forms[0].target = '_blank'; 
        setTimeout(function () { window.document.forms[0].target = ''; }, 0);
    }

This is my .aspx page: and i want to use it with update panel please help

<asp:ScriptManager ID="ScriptManager1" runat="server"
</asp:ScriptManager>
<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:Button ID="btnAssign" runat="server" Text="Assign" OnClientClick="SetTarget();" OnClick="btnAssign_Click"/>
     </ContentTemplate>
</asp:UpdatePanel >

i want to use it with update panel please help me if there any solution

最佳答案

如果您注意到您的 Javascript 代码存在语法错误,那么您的代码将运行良好。您缺少一个结束 } 来定义您的函数。如果没有它,您将收到意外的输入结束错误。 此外,在实际提交表单之前,您不会打开新选项卡。

这段代码可以工作:

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <script>
        function SetTarget() {
            document.forms[0].target = "_blank";
            console.log("Foo");
            document.forms[0].submit();

        }
    </script>
    <asp:UpdatePanel runat="server">
        <ContentTemplate>
            <asp:Button ID="btnAssign" runat="server" Text="Assign" OnClientClick="SetTarget();" />
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

关于javascript - 我想在 asp updatepanel 中使用这个 javascript 函数,详细信息如下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47323658/

相关文章:

javascript - 如何在 ASP.NET 中异步调用 Web 方法(后面的 SharePoint)

c# - 从 double 转换为十进制时避免 OverflowException

javascript - 如何为Each() 类创建点击监听器

javascript - 如果我知道对象的一个​​字段的值,如何从数组中删除对象?

javascript - Promise 应该被错误或字符串拒绝吗?

c# - MVVM基金会: How to close Application Window from ViewModel

c# - 查看我的网页的人数

c# - SomePanel.Controls 中的 foreach Control ctrl 未获取所有控件

asp.net - RadAsyncUpload 最大文件大小

javascript - 除非指定 'write' 选项,否则计算错误 : Cannot write a value to a ko.。如果你想读取当前值,不要传递任何参数