Solved

Creating Pop Windows in ASPNET C#

Posted on 2004-08-14
2
329 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Read about why website design really matters in today's demanding market.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now