Sumanta
Sumanta

Reputation: 313

How to open a aspx page as Modal popup

How to open a aspx page as Modal popup.

  1. Test.aspx should open like a modal popup.
  2. Let Test1.aspx has one button. On click it should populate Test.aspx page as Modal popup.

    Here is my button:

    <asp:Button ID="Button1" runat="server" Text="Fill Form in Popup" />
    

NOTE: Test.aspx : Normal aspx page but Test1.aspx: Parent page Contain master page.

Upvotes: 5

Views: 67924

Answers (4)

Arafat
Arafat

Reputation: 1400

If you want to open this as jQuery model dialog, see this post

Otherwise, If you want to open this page in a Modal Dialog you can use the following code to open it up. This examples use window.showModalDialog method of javascript. To find details how to use you can refer here.

      <script>
        function fnRandom(iModifier) {
          return parseInt(Math.random() * iModifier);
        }

        function fnSetValues() {
          var oForm = document.getElementById('oForm');
          var iHeight = oForm.oHeight.options[oForm.oHeight.selectedIndex].text;

          if (iHeight.indexOf("Random") > -1) {
            iHeight = fnRandom(document.body.clientHeight);
          }

          var sFeatures = "dialogHeight: " + iHeight + "px;";
          return sFeatures;
        }

        function fnOpen() {
          var sFeatures = fnSetValues();
          window.showModalDialog("test.aspx", "", sFeatures)
        }
      </script>

Upvotes: 1

Sunil Devre
Sunil Devre

Reputation: 384

Try this simple javascript to open aspx page in new window /popup

window.open("http://www.google.com/");
window.open("~/mypage.aspx");

or

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('YourPage.aspx?Param=" + ParamX.ToString() + "');",true);

Or if you have a button you can use it as below:

Button1.OnClientClick="javascript:window.open('YourPage.aspx?Param=" + ParamX.ToString() + "');";

hope this will help you otherwise use Ajax modal popup.

Upvotes: 0

Jalpesh Vadgama
Jalpesh Vadgama

Reputation: 14216

You can either use modal popup extender like below.

<cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="Button1"
CancelControlID="Button2" BackgroundCssClass="Background">
</cc1:ModalPopupExtender>

Reference : http://www.c-sharpcorner.com/UploadFile/cd7c2e/open-a-new-web-form-in-the-model-popup-of-Asp-Net-applicatio/

Or you can use jquery for opening a modal dialog with asp.net something like.

$(document).on("click", "#LoadDialogButton", function () {

var url = "DialogContentPage.aspx";
var divId = " #MainContentDiv";

var q1 = "?inp1=" + $("#Input1").val();
var q2 = "&inp2=" + $("#Input2").val();

url = url + q1 + q2 + divId; //url in the form 'DialogContentPage.aspx?inp1=xx&inp2=yy #MainContentDiv'

$('<div id=DialogDiv>').dialog("destroy");

$('<div id=DialogDiv>').dialog({
    dialogClass: 'DynamicDialogStyle',
    modal: true,
    open: function () {
        $(this).load(url);           
    },
    close: function (e) {
        $(this).empty();
        $(this).dialog('destroy');
    },
    height: 350,
    width: 540,
    title: 'Dynamic Dialog'

});

});

Reference: http://www.codeproject.com/Articles/488312/jQuery-Modal-Dialog-with-Dynamic-Content

Upvotes: 0

Vikas Rana
Vikas Rana

Reputation: 1999

Use ClientScript.RegisterStartupScript,try this

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim query As String = "test.aspx" 
        Dim newWin As String = "window.open('" & query & "');"
        ClientScript.RegisterStartupScript(Me.GetType(), "pop", newWin, True)

End Sub

Upvotes: 0

Related Questions