C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Open new window in Asp.NET in .net way


Posted Date: 19 Oct 2004    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: Rajeev Member Level: Silver    
Rating: 1 out of 5Points: 5



Opening a new window in ASP.NET

Just create a Class file and put this code

Public Shared Sub Opennewwindow(ByVal Opener As system.Web.UI.WebControls.WebControl, ByVal PagePath As String)

Dim Clientscript As String

Clientscript = "window.open('" & PagePath & "')"

Opener.Attributes.Add("Onclick", Clientscript)

End Sub


We can pass so many values to that new window function.

Just call this function Opennewwindow

Actually the client side script is working for this when we click on the web control but this is just the .net way . what it does is, It will configure the opener webcontrol to make a client side "window.open" call. Please note that opener control can be any asp.net webcontrol which support client side "onclick".

projectname.classname.Opennewwindow(Button1,"http://voiceofkerala.com")

This is a simple article but i write this for my friends which are students who are looking this code. Hello Just use this code, if u want to know more about opening windows in diffrent style u can apporach me not only opening windows but if need help for Asp.net, I am not an expert but i think i can help students who have just simple doubts

I am Rajeev working as a Asp/vb .net programmer. if You have any Questions ,Feel Free to contact: rajeev_gt@rediffmail.com



Responses

Author: Atal Bihari Upadhyay    19 Oct 2004Member Level: Gold   Points : 0
Very good article. Keep it up.


Author: Santhosh John W    20 Oct 2004Member Level: Bronze   Points : 0
Nice stuff


Author: Ammar Ahmed Siddiqui    21 Oct 2004Member Level: Silver   Points : 0
Was looking for this thing.
Thanks
Ammar


Author: Anjali Shah    21 Nov 2004Member Level: Silver   Points : 0
Short but very useful.


Author: Pradeep    29 Nov 2004Member Level: Bronze   Points : 0
hi rajeev,
I tried to use the code u suggested and i have noticed that i have to click the button control twice for the page to be opened in a new window because the first time the control is clicked it assigns the OnClick event that is written in code behind. how to achieve the functionality in a single click rather than in 2 clicks?

my prob:

i have a datagrid with multiple rows each row is having a check box. when the user selects a check box for a row and clicks a button i want to open a new window and display the new page for each row selected. how to do this?

Thank you,

--Pradeep


Author: Andy Starzomski    10 Dec 2004Member Level: Bronze   Points : 0
On the web page where the buttons appear I have initialized the OpenNewWindow class by sending the proper parameters. Once this was done I only had to click the button once inorder for the new window to open, otherwise I had to click it twice. I hope this helps

Andy


Author: Uncle Buck    15 Dec 2004Member Level: Bronze   Points : 0
There is a much simpler way of doing this. In the creator method of your extended web control class (such as "MyImageButton") just put a single line of code as follows:

Attributes.Add("openWindow('http://www.mysite.com','MyTitle','640','480');

Makes sense to keep your code clean. Now, you just decalre your image button to be of type "MyImageButton" and all done.


Author: Joriz     25 Dec 2004Member Level: Bronze   Points : 0
this is a good one. but is there anyway to remove address bars, toolbars menus?? and pass the height and width of the new window.
thanks.


Author: vishal     05 Jan 2005Member Level: Gold   Points : 0
Very short and effective code.
there is no need to CLICK Twice
u just need to change a little:
add attributes of button_click when the page loads.
than it will work with single click



Author: Jex H    31 Jan 2005Member Level: Bronze   Points : 0
Hi All,

Has anyone been able to get around the double clicking to open new window?

I have tried to set the attributes at Page Load event as shown

btnFind.Attributes.Add("OnClick", "Clientscript")

where Clientscript is

Clientscript = "window.open('" & strUrl & "')"

This method does not work or have I miss something.

Thanks.


Author: vishal     01 Feb 2005Member Level: Gold   Points : 0
just put following into page load:
Dim str As String = "fullimage.aspx?id=" & prodid & ""
'opennewwindow is function with 2 values (string(str)
'and control(button1))
Opennewwindow(Button1, str)
after registering when button1's click event write the code:
Dim str As String = "fullimage.aspx?id=" & prodid & ""
Opennewwindow(Button1, str)

it will work with a single click




Author: vishal     01 Feb 2005Member Level: Gold   Points : 0
just put following into page load:
Dim str As String = "fullimage.aspx?id=" & prodid & ""
'opennewwindow is function with 2 values (string(str)
'and control(button1))
Opennewwindow(Button1, str)
after registering when button1's click event write the code:
Dim str As String = "fullimage.aspx?id=" & prodid & ""
Opennewwindow(Button1, str)

it will work with a single click




Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Web Gardening
Previous Resource: Time elasped in page execution
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use