Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Creating Pop Windows in ASPNET C#

Posted on 2004-08-14
2
337 Views
Last Modified: 2006-11-17
Dear Expert,
  I am fairly new to .net develop using C# and ASPNET. I have an application were I need to create pop-up window for quick help referencing and hints. I wanted to use either a hyperlink or a link webform control. I am not sure how to go about using either of these control create the desired a pop-up window functionality. I am  open to suggestions.

Thanks for the help


-K
0
Comment
Question by:Khopkins32
2 Comments
 
LVL 18

Accepted Solution

by:
tusharashah earned 125 total points
ID: 11802706
For the Web server controls, you cannot simply use the HTML syntax to add client-side event handling. The reason is that for some controls, ASP.NET already uses client-side event handling to perform automatic postback operations. The preferred way to add client-side evnet handling code for Web server controls is via the use of the Attributes property of the Web server controls. For example, the following code fragment attaches the someClientCode() client-side method to the OnMouseOver attribute of the btnSubmmit button (POP-UP)
--------------------------------------------------------------------------------
Insert a <script> element under the <head> element to add the client-side function as shown here:

<head>
...
      <script language='javascript'>
            function btnSubmit_ClientClick()
            {
             alert("YOU CLICKED btn ") ;
            }
      </script>

</head>

- Now add an onClick attribute to the btnSubmit control's attribute collection to execute the client-side function added up above. Add following code in Page_Load of your code-behind

private void Page_Load(object sender, System.EventArgs e)
{
      btnSubmit.Attributes.Add("onclick", "btunSubmit_ClientClick();");
}


}

--------------------------------------------------------------------------------

You can also setup other javascript function like this
-tushar
0
 
LVL 3

Expert Comment

by:bigjim2000
ID: 11807647
Here's what I'd do:

First, put the following code somewhere in the <head></head> tags:
<script language="javascript">
function popUp(URL,xsize,ysize)
{
      day = new Date();
      id = day.getTime();
      eval("page" + id + " = window.open(URL, '" + id + "', 'width=' + xsize + ',height=' + ysize + ',left = 835.5,top = 475.5');");
}
</script>

Lets say you have some link on your page.  Normally, the code would look as follows:
<a href="somepage.html">My other page</a>

Now lets say you want this page to pop-up when you load your server control (which is what I'm assuming you want to do).
Your link would now look like this:
<a href="javascript:popUp('somepage.html', '100', '100');">My other POPUP page</a>

Note, the 100 and 100 are the x and y dimensions of the new page.  This is handy if you want your pages to appear a certain size.

Hope this helped.

-Eric
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question