Rectangle 27 0

c asp ModalPopupExtender is getting closed when page is getting postback?


<style type="text/css">
        .hide
        {
            display:none;
        }
    </style>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ModalPopExample.aspx.cs" Inherits="WebApp.ModalPopup.ModalPopExample" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Test Page</title>
    <style type="text/css">
        .hide
        {
            display:block;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
        <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </ajaxToolkit:ToolkitScriptManager>
        <asp:Panel ID="Panel1" CssClass="hide" runat="server" BorderColor="Red" BorderStyle="Dashed" BorderWidth="3px">
            Are you sure?
            <br />
            <asp:Button ID="btnok" runat="server" Text="OK" />
            <asp:Button ID="btncancel" runat="server" Text="Cancel" />
        </asp:Panel>
        <asp:Button ID="btnShow" runat="server" Text="Show Modal" />
        <asp:Image ID="Image1" ImageUrl="~/image_loader.ashx" runat="server" />
        <ajaxToolkit:ModalPopupExtender ID="btnShow_ModalPopupExtender" DropShadow="true" OkControlID="btnok" CancelControlID="btncancel" PopupControlID="Panel1" runat="server" DynamicServicePath="" Enabled="True" TargetControlID="btnShow">
        </ajaxToolkit:ModalPopupExtender>        
    </form>
    <script>
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_pageLoaded(function () {
            console.log('loaded');
        });
    </script>
</body>
</html>
<script>
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(function () {
        console.log('loaded');
        var div = document.getElementById('Panel1');
        div.className = '';
    });
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;

namespace WebApp.ModalPopup
{
    /// <summary>
    /// Summary description for image_loader
    /// </summary>
    public class image_loader : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/jpg";
            var imagePath = context.Server.MapPath("~/images/windows_xp_bliss-wide.jpg");
            Thread.Sleep(20000);
            context.Response.TransmitFile(imagePath);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

A word of advice: don't just post a question because you are stuck. Try to present a "fake" problem which "models" your actual problem. It helps us re-create the issue you are facing and also helps people out here to provide better answers. And when you are at it, chances are that you might itself figure out a solution. :)

Ascx is supposed to be thought of something like a "reusable" component. Its not a page in itself. Anyway I don't quite follow how your problem has run into page postbacks. It was never part of the original question. Seems like you need to open another question out here.

My doubt is, I am writing __doPostBack("", ""); for getting postback onclick of treeview in another page( ascx usercontrol). But we are displaying the ascx page in another(main) page via modelpopupextender.Now the __doPostBack("", ""); method is applying for main page not for that ascx page I guess.. What do you say ??

Notice that the image is loaded via a handler file (ashx):

The popup flickers for a while. The most simple workaround you can do is hide the element at first itself (via css) and some javascript is required to remove that css when the web page if fully loaded.

When you ajax client scripts all finish loading...find the control and remove the above class on the element.

here is what I did to re-create your issue. I've created a web page with a modal popup extender.

Note
Rectangle 27 0

c asp ModalPopupExtender is getting closed when page is getting postback?


function postbackOnCheck(e) {
    var evt = e || window.event;
    var o = evt.target || evt.srcElement;
    if (o.tagName == 'INPUT' && o.type == 'checkbox' && o.name != null && o.name.indexOf('CheckBox') > -1) {
        __doPostBack('<%=updTree.ClientID %>', 'Refresh:0,1,2');
    }
}
<div id="form" runat="server">
<asp:UpdatePanel ID="updTree" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:TreeView ID="tvFolderSelect" runat="server" RootNodeStyle-ForeColor="Black"
            CssClass="foldertree" LeafNodeStyle-ForeColor="Black" LeafNodeStyle-Font-Bold="false"
            ParentNodeStyle-ForeColor="Black" Width="100%" Style="margin: 3px 0 0 -16px;"
            OnTreeNodePopulate="tvFolderSelect_TreeNodePopulate" OnTreeNodeCheckChanged="tvFolderSelect_TreeNodeCheckChanged"
            ShowCheckBoxes="All" onclick="postbackOnCheck(event);">
            <LeafNodeStyle Font-Bold="False" ForeColor="Black" CssClass="foldertreeleafnode"
                ImageUrl="~/images/img_dms/sm_fldr.png" />
            <ParentNodeStyle Font-Italic="True" ImageUrl="~/images/img_dms/sm_fldr.png" Font-Underline="True"
                CssClass="foldertreeparentnode" />
            <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="0px"
                NodeSpacing="0px" VerticalPadding="0px" />
            <RootNodeStyle ForeColor="Black" CssClass="foldertreerootnode" />
            <SelectedNodeStyle Font-Underline="False" HorizontalPadding="0px" VerticalPadding="0px" />
        </asp:TreeView>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="tvFolderSelect" EventName="TreeNodeCheckChanged" />
    </Triggers>
</asp:UpdatePanel>

I used AsyncPostBackTrigger to run the server side code and changed the __DoPostBack method parameters. now my treeview design is

Now my panel is not closing while getting postback

Note
Rectangle 27 0

c asp ModalPopupExtender is getting closed when page is getting postback?


I tried this. Still it is behaving like before. My doubt is, I am writing __doPostBack("", ""); for getting postback onclick of treeview in another page( ascx usercontrol). But we are displaying the ascx page in another(main) page via modelpopupextender.Now the __doPostBack("", ""); method is applying for main page not for that ascx page I guess.. What do you say ??

Note