简体   繁体   English

在ascx.cs中使用来自ascx文件的脚本

[英]Script from ascx file use in ascx.cs

I have one script from ascx file to hide the popup page. 我有一个来自ascx文件的脚本来隐藏弹出页面。 This script currently use when user click cancel button. 用户单击“取消”按钮时当前使用此脚本。

Script in ascx file: ascx文件中的脚本:

<script>
function HidePopup() {
    $find("mpeDiscountedProducts").hide();
    return false;
}

I want to use this script in ascx.cs (behind code) to hide the popup when user click on select button. 当用户单击选择按钮时,我想在ascx.cs(代码后面)中使用此脚本来隐藏弹出窗口。

Below code that i want to place the script: 下面我要放置脚本的代码:

 protected void btnSelect_Click(object sender, EventArgs e)
    {
        RemoveDiscountedItemsFromCart();
        AddToCart(1);
        this.Page.GetType().InvokeMember("CallFromDiscountProduct", System.Reflection.BindingFlags.InvokeMethod, null, this.Page, null);

    }

Thanks. 谢谢。

Call 呼叫

Page.ClientScript.RegisterStartupScript(
    this.GetType(), "Hide_mpeDiscountedProducts", "HidePopup()", true);

Documentation 文献资料

"Hide_mpeDiscountedProducts" is an arbitrary key that identifies the script so that you can avoid registering it twice if another control on the page might potentially register the same script. "Hide_mpeDiscountedProducts"是标识脚本的任意键,因此,如果页面上的另一个控件可能潜在地注册相同的脚本,则可以避免将其注册两次。

Your button is going to trigger a postback so the page is going to refresh. 您的按钮将触发回发,因此页面将刷新。 When the page refreshes it will contain a <script> tag containing a call to HidePopup() . 页面刷新时,它将包含<script>标记,其中包含对HidePopup()的调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM