Showing Small Window

  • Thread starter Thread starter Jonathan Wood
  • Start date Start date
J

Jonathan Wood

I'd like to have some help buttons on my page pop up a smaller browser
window with the help text and perhaps a close button.

Does anyone have any examples of this, or suggestions on how to get started?

Thanks.

Jonathan
 
The quick, down and dirty version is to write a popup that works in
Javascript. Then, move the text from the JavaScript block into a
StringBuilder, line by line, with line returns vbcrlf in VB and "\r\n" in
C#. You can even configure to pull up specific records, if you desire.

Then, put the text in a literal control and attach to a container, like a
panel that does that work.

Here is the cheap, down and dirty example (VB.NET) with a hyperlink to open
the page (added onClick attribute).

Dim builder As New StringBuilder()
builder.Append("<script language='Javascript' type='text/javascript'>")
builder.Append(ChrW(10) & ChrW(13))
builder.Append("myWindow = window.open(")
builder.Append(GetUrl())
builder.Append(");")
builder.Append(ChrW(10) & ChrW(13))
builder.Append("</script>")
builder.Append(ChrW(10) & ChrW(13))
Dim lit As New LiteralControl(builder.ToString())
pnlJavaScript.Controls.Add(lit)
hypCertificate.Attributes.Add("onclick", GetWindowOpen())

A more correct version would emit the JavaScript instead of creating a
literal and adding.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
 
I'm not real clear on when this would occur. Do I do this when the page
loads or something?

Also, you stated that a more correct approach would be to emit the
JavaScript. I don't quite understand how that differs as your code appears
to emit JavaScript. (I am interested in the most "correct" approach.)

I'm using C# BTW, although the two languages are pretty much the same.

Thanks.
 
I usually use C#, but find many beginners do not. :-)

You can set it up with Page_Load if it is popping up when you initially open
the page. You can also place it in any control event, like when a user
clicks a button.

When you place items on a page, you have the ability to use the Register
script events. Look up RegisterClientScript, for example, to register a
client script. What control you add it to really depends on the nature of
the application.

Adding a control is "less correct" to a purist, but I feel if something
works well and is easy to understand, it is fine. In either case, create the
popup script in its own routine so you can reuse it. It is easy to teach
someone else how to do it, which is very beneficial in the application I am
currently working on.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
 
I usually use C#, but find many beginners do not. :-)

Heh, well, I'm only a beginner to ASP.NET (as you probably know).
You can set it up with Page_Load if it is popping up when you initially
open the page. You can also place it in any control event, like when a
user clicks a button.

I'm not sure I understand how well I understand what is happening with that
code. I'll try it in Page_Load and look at the HTML generated.
When you place items on a page, you have the ability to use the Register
script events. Look up RegisterClientScript, for example, to register a
client script. What control you add it to really depends on the nature of
the application.

Adding a control is "less correct" to a purist, but I feel if something
works well and is easy to understand, it is fine. In either case, create
the popup script in its own routine so you can reuse it. It is easy to
teach someone else how to do it, which is very beneficial in the
application I am currently working on.

I'll look into those items a bit more.

Thanks.
 
Greg,

I tried this but guess I still don't get what we're doing.

What is GetUrl()? What is GetOpenWindow()? Shouldn't the script have a name
that is associated with the onclick attribute?

Thanks.
 
Back
Top