0

Hi I want to open popup window in button click event without using j-query in asp.net C#. This is simple task i am familiar with Asp.Net MVC. But i am not familiar in Asp.Net so only i am struggling for this simple task.

Please any one tell me how to open popup window by button click event without using jquery in asp.net C#.

My web form

SpecilalityMaster.Aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="specialitymaster.aspx.cs" Inherits="popupwindow.admin.specialitymaster" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <form id="frmPopupExample" runat="server">

<asp:Button ID="btnOpenPopupWindow" 
            runat="server" 
            Text="Open Popup Window" OnClick="btnOpenPopupWindow_Click" 
             />
 </form>

<div class="popup">
     <asp:TextBox ID="_lname" runat="server"></asp:TextBox>

        <asp:Button ID="Button1" 
            runat="server" 
            Text="save" OnClick="Button1_Click" 
             />
    </div>
 </asp:Content>

specialitymaster.aspx.cs

public partial class specialitymaster : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnOpenPopupWindow_Click(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {

    }
}

i just tried simply. i designed one button and one popup window.if i click open popup window in button click event i need to open popup window. i donno it is possible or not.i created button click event in CS page but i donno how to call that popup window name in button click event .

example

Desirable result: Please see image.

7
  • do you use bootstap? Commented Jan 4, 2018 at 16:50
  • in asp.net how to use bootstrap Commented Jan 4, 2018 at 16:54
  • 1
    @VladimirChikrizov What does bootstrap have to do with opening a new window? Is plain javascript ok? Commented Jan 4, 2018 at 16:55
  • @VladimirChikrizov is it possible to use bootstrap in asp.net then what is the need of bootsrap for my question Commented Jan 4, 2018 at 16:55
  • 1
    just use javascript, it's very straight forward Commented Jan 4, 2018 at 17:01

3 Answers 3

2

If I understand you correctly, you don't need a popup, you just trying to activate some div on your page. You will need to make this div server side

<div class="popup" runat="server" style="display:none" id="divPop">
 <asp:TextBox ID="_lname" runat="server"></asp:TextBox>

    <asp:Button ID="Button1" 
        runat="server" 
        Text="save" OnClick="Button1_Click" 
         />
</div>

and then in your server side click

protected void btnOpenPopupWindow_Click(object sender, EventArgs e)
{
  divPop.Attributes.Add("style", "display:block);
}

this will make your div visible

EDIT better solution in your case would be using asp panel instead of div.

<asp:panel id="divPop" visible="false" runat="server">
    <asp:TextBox ID="_lname" runat="server"></asp:TextBox>

      <asp:Button ID="Button1" 
    runat="server" 
    Text="save" OnClick="Button1_Click" 
     />
</asp:panel>

and then you will be able to manipulate visibility in your server side code very easy

protected void btnOpenPopupWindow_Click(object sender, EventArgs e)
{
  divPop.Visible=true;
}
Sign up to request clarification or add additional context in comments.

4 Comments

yuri i have attached one eg image in question please see that like that only i want to achieve
how to open as popup which is mention same as like in that image .Visible is just show and hide that div i need open as popup
Your panel lacks the runat="server" attribute.
i added that runat="server". now what i need is how to open as POPUP.Visible just hide and show div in same parent window . i need to open as popup window same as like mention in that image
0

you are using server side control in your code.

<asp:Button ID="btnOpenPopupWindow" 
        runat="server" 
        Text="Open Popup Window" OnClick="btnOpenPopupWindow_Click" 
         />

click of this button will trigger immediate post to the server and server (your ASP.NET application) will handle the event. The only way you will be able to open a popup from the server if you will register script to do this. Your CLick should look something like

 protected void btnOpenPopupWindow_Click(object sender, EventArgs e)
{
  ClientScript.RegisterStartupScript(this.GetType(), 
    "yourWindowName", 
     String.Format("<script>window.open('{0}');</script>", yourURL));
}

3 Comments

in your URL place what ihave to give yuri
for the testing purpose put stackoverflow.com and later on replace with the url that you are really want to open
yuri i want to open popup window in same window not as separate window. eg in my code i mention <div class="popup"> in button click event i open this div as popup window
-1

Use this:

var DefineWindowSize= "location=yes,height=570,width=520,scrollbars=yes,status=yes";
var URL = "https://www.google.com";
var win = window.open(URL, "_blank", DefineWindowSize);

Create a function and add it inside the function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.