简体   繁体   中英

Script from ascx file use in ascx.cs

I have one script from ascx file to hide the popup page. This script currently use when user click cancel button.

Script in ascx file:

<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.

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.

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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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