Solved

Open JavaScript window from C#.NET

Posted on 2008-10-11
1
647 Views
Last Modified: 2013-12-17
This function opens the page in a new window... I would like to control window size, location, toolbars, etc... I want the window to only have the address bar, nothing else...
protected void rHotels_ItemCommand(object source, RepeaterCommandEventArgs e)

    {

        if (e.CommandArgument != null)

        {

            StringBuilder openWindow = new StringBuilder();

            openWindow.Append("<script>open('");

            openWindow.Append("HotelDetail.aspx?HotelID=" + e.CommandArgument);

            openWindow.Append("');</script>");

            Page.RegisterStartupScript("OpenWindows", openWindow.ToString());
 
 
 

        }

    }

Open in new window

0
Comment
Question by:conrad2010
1 Comment
 
LVL 8

Accepted Solution

by:
rlh68 earned 500 total points
ID: 22695154

The below code will do what you want, notice the forth line has changed. Additionally, it sizes and positions the window too. Remove the height, width, top, and left if you don't want to size and/or position the new window.

StringBuilder openWindow = new StringBuilder();
openWindow.Append("<script>open('");
openWindow.Append("HotelDetail.aspx?HotelID=" + e.CommandArgument);         openWindow.Append("','WindowTitle','width=500,height=500,left=50,top=50,toolbar=0,resizable=0,location=0,status=0,menubar=0,scrollbars=0');</script>");
Page.RegisterStartupScript("OpenWindows", openWindow.ToString());


To learn more...
http://msdn.microsoft.com/en-us/library/ms536651(VS.85).aspx

http://www.javascripter.net/faq/openinga.htm
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Objects on Same Line 2 18
Angular - disable input field on page load 4 14
C# guarantee sql connection close 6 30
Crystal reports vb.net 2 16
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

895 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

14 Experts available now in Live!

Get 1:1 Help Now