Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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.

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)

Posted (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 by Rankun
Posted

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)");
     }
}

Posted
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)");
}

Posted

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>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...