Can you use redirect to open new window"?

Rankun

Newcomer
Joined
Jan 14, 2003
Messages
17
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
 
Here is an example of the javascript:
Code:
<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.
Code:
Me.lbtnAgreement.Attributes.Add("onClick", "return newWindow();")

Mike55.
 
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
 
Last edited:
You would have to be a bit more clever:

For the JavaScript:
Code:
<script language = "javascript" type="text/javascript">
        function openWindowWithValue(link)
        {
              if(link)
              {
                   window.open(val);
              }
        }
</script>

HTML ASP code:
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#)
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)");
      }
}
 
HJB417 said:
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:

C#:
//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)");
}
 
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>
 
Back
Top