ASP.NET is a server-based platform, which means the code you write executes on the web server instead of in the client's browser. This approach ensures that your code is kept secure from prying eyes, and it sidesteps most browser-compatibility issues. However, it also introduces some unavoidable limitations.
- Insert the script block programmatically. To do this, use either the
The next three sections demonstrate this technique.
- Showing a Pop-Up Window
window.open()function requires three parameters:
- The link for the new page.
- The frame name of the window.
- A comma-separated string of attributes that will configure the style and size of the pop-up window. These can include the
widthattributes (with pixel values); the
scrollbarattributes (set to
no, depending on whether you want to display these elements); and the
resizableattribute (set to
no, depending on whether you want a fixed or resizable window border).
In VB .NET, the code is virtually identical:
You can use this code in any event handler. For example, you might want the window to appear when the page first loads, or after the user clicks a button or performs another action. In any case, the pop-up window will only appear the next time the page is returned to the user. If you want it to reappear the next time the user takes an action, you'll need to create and register the script block again.
Note that when the script block is added to the page, it's identified with a descriptive name (in this case, "PopupScript"). If you add a script block with the same name multiple times, it will only be added to the page once.
- Changing Control Focus
The ASP.NET web controls provide a
Here's the function you will need in C#:
Here's the same function rewritten for VB .NET:
You can now call the custom
SetFocus()function from any event handler to change the control focus as needed:
Remember, the focus change won't take effect until the page is rendered and sent back to the browser.
- Handling Frame Navigation
Frames allow you to display more than one HTML document in the same browser window. In the case of a site with a navigational menu, you could split the page vertically into two frames. The frame on the left would contain the navigation control, while the frame on the right would show the selected content. (For more information about frames, refer to this HTML Frames tutorial or this Web Authoring FAQ.)
The C# code is virtually identical:
Matthew MacDonald is a developer, author, and educator in all things Visual Basic and .NET. He's worked with Visual Basic and ASP since their initial versions, and written over a dozen books on the subject, including The Book of VB .NET (No Starch Press) and Visual Basic 2005: A Developer's Notebook (O'Reilly). His web site is http://www.prosetech.com/.
O'Reilly & Associates recently released (August 2003) ASP.NET in a Nutshell, 2nd Edition.
Sample Chapter 6, "User Controls and Custom Server Controls," is available free online.
For more information, or to order the book, click here.
Return to ONDotnet.com