0

In my Web application, I am dynamically adding a Button named as "Click Me !". At Stage 1 , when the Button is clicked, it has to show a alert box . At Stage 2, it has to show a Popup. I use ModalPopupExtender to achieve popup. The Problem is, the popup is just blinked once, instead of Displaying it constantly. Given below my codes...can any one help me to get rid of this ?

Page_OnLoad():
**************
     Button Button1=new Button();
     Button1.Text="Click Me !";
     Button1.ID="LogBut";
     Controls.Add(LogBut);

Stage 1:

      JavaScript:
      ***********
          function alert()
          {
             alert("Stage 1");
          }

      Code behind:
      ************
       LogBut.Attributes.Add("OnClick", "alert();");

Stage 2:

      JavaScript:
      ***********
          var Modalpopup='<%=modalPermission.ClientID %>';
          function Popup()
          {
             $find(Modalpopup).show();
          }

     Design:
     *******
           <Ajax:ModalPopupExtender ID="modalPermission" runat="server" TargetControlID="Infield"
                   PopupControlID="divPermission"></Ajax:ModalPopupExtender>
           <asp:HiddenField ID="Infield" runat="server" />

     Code Behind:
     ************
           LogBut.Attributes.Add("OnClick", "Popup();");

Note: I am using the hidden field control's Id as ModaPopupExtender's TargetControlId. Am adding this button inside calendar control.

Screenshots of the calendar:

Design Page Code Behind

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
ognale88
  • 169
  • 3
  • 7
  • 19

1 Answers1

1

Modal popups do not remember that it's supposed to show after a popup. If you are attaching a popup show to a button, you have to disable the postback to the server. Most likely your problem is the button shows the modal, but also posts back, and on postback, the modal doesn't remember it's supposed to show. You can kill the postback by doing the following; set

UseSubmitBehavior='false'

on the server-side button, and then in the Popup function, do:

function Popup(e) {
   // stop button event propagation, which causes postback
   if (e.stopPropagation)
      e.stopPropagation();
   if (e.preventDefault)
      e.preventDefault();

   // show modal
}

And that should prevent a button postback to the server.

EDIT: Your function said Popup, but your javascript is rendering showpopup() as the function call. If that function doesn't exist (and spelled the exact same), it will never stop the postback.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257