Rankun Posted December 21, 2005 Posted December 21, 2005 I am trying to have 2 options when clicking a button that opens a web site. 1. Open in current browser. (This works) 2. Open in new browser. Here is what I am using. If chkbxNewWindow.Checked = True Then ????? Else Response.Redirect(HyperLink) End If *Note* Hyperlink is a variable containing a website address. Thanks again, Rankun Quote
HJB417 Posted December 21, 2005 Posted December 21, 2005 You cannot use Response.Redirect to open a new window. You'll need to use javascript. Quote
mike55 Posted December 21, 2005 Posted December 21, 2005 Here is an example of the javascript: <script language="javascript"> function newWindow(){ var doc = document.forms[0]; window.open("http://www.yahoo.com", "Welcome", "width=550, height=550, resizeable=0, menubar=no, scrollbars=no, status=yes, left=0 , top=0") } </script> You then add an onclick attribute to the button that you want to use to open the new window. Me.lbtnAgreement.Attributes.Add("onClick", "return newWindow();") Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Rankun Posted December 21, 2005 Author Posted December 21, 2005 (edited) Thanks, I don't use the html page much in my projects, guess I need to start learning that next. Anyway.. Is it possible to pass a variable from a dropdownlist (design mode) to the javascript for the hyperlink? IE Instead of "http://www.newegg.com", I am trying to use ddlHyperLink.SelectedItem.Text <script language="javascript"> var NewJavaHyperlink = "http://www.newegg.com"; function newWindow(){ var doc = document.forms[0]; window.open(NewJavaHyperlink) } </script> Thanks again, Rankun Edited December 22, 2005 by Rankun Quote
bri189a Posted December 22, 2005 Posted December 22, 2005 You would have to be a bit more clever: For the JavaScript: <script language = "javascript" type="text/javascript"> function openWindowWithValue(link) { if(link) { window.open(val); } } </script> HTML ASP code: <asp:DropDownList id="CustomerList" runat="server"></asp:DropDownList> I assume you can handle the bit about putting the values in the drop down list. Code Behind (c#) //Ensure you've wired up this event of coarse! private void CustomerList_PreRender(object sender, System.EventArgs e) { //You may not need the test for null, I don't remember...this just ensures you //don't wire up the javascript event twice because of ViewState if(CustomerList.Attributes["onchange"]==null || CustomerList.Attributes["onchange"]==string.Empty) { CustomerList.Attributes.Add("onchange", "openWindowWithValue('http://www.newegg.com/somepage.aspx?id=' + this.value)"); } } Quote
HJB417 Posted December 22, 2005 Posted December 22, 2005 Attributes.Add has the same effect as Attributes.set_Item. Attributes.set_Item internally just calls Attributes.Add. Quote
bri189a Posted December 22, 2005 Posted December 22, 2005 Attributes.Add has the same effect as Attributes.set_Item. Attributes.set_Item internally just calls Attributes.Add. You are correct on that...I was thinking of a past experiance where I had to add multiple items to a single attribute so I was doing += on the attribute had to make sure I hadn't already added a particular function somewhere else (had some crazy business rules that were a nightmare to code around). Thanks for the clarification. Just ignore that particular if statement it should read as: //Ensure you've wired up this event of coarse! private void CustomerList_PreRender(object sender, System.EventArgs e) { CustomerList.Attributes.Add("onchange", "openWindowWithValue('http://www.newegg.com/somepage.aspx?id=' + this.value)"); } Quote
Rankun Posted December 22, 2005 Author Posted December 22, 2005 Not sure what is happening here. Consider I am opening a book for most lines of code I write. :) I am used to writing VB6 code, not ASP and Javascript. In the javascript code what is link and val referring to or coming from? The C# code has me lost, never used C# before. Sorry for my lack of understanding. :( What I have is a dropdown list that is populated with URL's on load from a database connection. On change of the dropdown should redirect or open a website in a new window depending on if a checkbox is selected or not. Redirect works fine new window not working at all. What I was hoping is the javascript would work something like this (if it makes sense to anyone): <script language="javascript"> function newWindow(){ var doc = document.forms[0]; window.open(Global.NewJavaHyperlink) } </script> or <script language="javascript"> function newWindow(){ var doc = document.forms[0]; window.open(dropdownlist.selecteditem.text) } </script> Quote
HJB417 Posted December 22, 2005 Posted December 22, 2005 Here's some stuff to help you get up to speed on what we're talking about http://webmonkey.wired.com/webmonkey/98/04/index3a_page10.html?tw=programming http://www.netmechanic.com/news/vol3/javascript_no12.htm http://www.w3schools.com/htmldom/dom_obj_select.asp http://www.quirksmode.org/index.html?/js/intro.html http://www.w3.org/TR/REC-html40/interact/scripts.html http://www.faqs.org/docs/htmltut/forms/_SELECT_onChange.html http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiattributecollectionclasstopic.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiattributecollectionclassaddtopic.asp Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.