通过调用CodeBehind调用JavaScript打开弹出窗口

发布于 2025-02-06 03:13:37 字数 1240 浏览 1 评论 0原文

我正在尝试通过在按钮点击事件中调用CodeBehind(vb.net)中的JavaScript函数打开弹出窗口。

想法是我单击按钮,按钮单击事件会做很多事情,然后启动JavaScript功能以打开弹出窗口。

JavaScript:

function openSync() {
            var companyId = $("#<%= txtCompanyID.ClientID%>").val();
            $find("<%= RadWindowManager1.ClientID%>").open("SyncDatabases.aspx?CompanyID=" + encodeURIComponent(companyId), "winSyncProcess");
        }

我可以在CodeBehind中调用opensync函数:

 ScriptManager.RegisterStartupScript(Me, Me.GetType(), "open", "openSync();", True)

尝试此操作时,我将获得typeerror:无法读取NULL的属性(读取'open'') error。

但是,如果我将按钮本身上的onClientClick属性属性属于

OnClientClick="openSync(); return false;"

JavaScript,则可以按照自己的方式出现弹出窗口,但是这样做会忽略CodeBehind按钮单击事件,并且不做任何事情应该这样做。

我正在使用RadwindowManger:

    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
        <Windows>
            <ic:PopupWindow ID="winSyncProcess" runat="server" Width="800px" Height="600px" OnClientClose="OnSyncProcessClose"></ic:PopupWindow>
        </Windows>
    </telerik:RadWindowManager>

I am trying to open a popup window by calling a JavaScript function in CodeBehind (vb.net) on a button click event.

The idea is that I click the button, the button click event does a bunch of stuff, then fires the javascript function to open the popup window.

Javascript:

function openSync() {
            var companyId = $("#<%= txtCompanyID.ClientID%>").val();
            $find("<%= RadWindowManager1.ClientID%>").open("SyncDatabases.aspx?CompanyID=" + encodeURIComponent(companyId), "winSyncProcess");
        }

I can call the openSync function in CodeBehind using:

 ScriptManager.RegisterStartupScript(Me, Me.GetType(), "open", "openSync();", True)

When attempting this, I am getting a TypeError: Cannot read properties of null (reading 'open') error.

BUT, if I assign the OnClientClick property on the button itself to

OnClientClick="openSync(); return false;"

the Javascript works fine, and the popup window appears as it should, but doing so ignores the CodeBehind button click event and doesn't do the things it's suppose to do.

I am using a RadWindowManger:

    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
        <Windows>
            <ic:PopupWindow ID="winSyncProcess" runat="server" Width="800px" Height="600px" OnClientClose="OnSyncProcessClose"></ic:PopupWindow>
        </Windows>
    </telerik:RadWindowManager>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七婞 2025-02-13 03:13:37

最终使用
scriptManager.registerStartupScript(me,me.getType(),“ settimeout(function(){opensync();},100),100);”,opensync,true)>
这解决了这个问题。

Ended up using
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "setTimeout(function () { openSync(); }, 100);", openSync, True)
and that solved the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文