【问题标题】:Script from ascx file use in ascx.csascx 文件中的脚本在 ascx.cs 中使用
【发布时间】:2017-05-31 02:04:46
【问题描述】:

我有一个来自 ascx 文件的脚本来隐藏弹出页面。此脚本当前在用户单击取消按钮时使用。

ascx 文件中的脚本:

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

我想在 ascx.cs(代码后面)中使用这个脚本来在用户单击选择按钮时隐藏弹出窗口。

下面是我要放置脚本的代码:

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

    }

谢谢。

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    打电话

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

    Documentation

    "Hide_mpeDiscountedProducts" 是标识脚本的任意键,因此如果页面上的另一个控件可能注册相同的脚本,您可以避免注册两次。

    您的按钮将触发回发,因此页面将刷新。当页面刷新时,它将包含一个 &lt;script&gt; 标记,其中包含对 HidePopup() 的调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-18
      • 1970-01-01
      • 2011-10-15
      • 2012-05-08
      相关资源
      最近更新 更多