4 Replies - 1937 Views - Last Post: 29 July 2010 - 08:18 PM Rate Topic: -----

#1 nmges  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-June 10

open a window on a page in vwd 2008

Posted 24 July 2010 - 11:29 PM

Just want to know how do you open a window on the same page, and not to open a new page,
see I have a drop down list, when clicked a list name, it will open a new window on the drop down list page, the page is still there, just will open a new window. The response.redirect is to open a new page, how about just to open a new window on the same page? Thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: open a window on a page in vwd 2008

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: open a window on a page in vwd 2008

Posted 25 July 2010 - 08:37 AM

Use Javascript to open a new window.

Open new window.
Was This Post Helpful? 0
  • +
  • -

#3 nmges  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-June 10

Re: open a window on a page in vwd 2008

Posted 25 July 2010 - 06:28 PM

View PostJayman, on 25 July 2010 - 07:37 AM, said:

Use Javascript to open a new window.

Open new window.


 Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Select Case DropDownList1.Text
            Case "First Meeting Room"
                'Response.WriteFile("http://localhost:52952/RoomSetting/FirstMeetingRoom.aspx")
                Response.Redirect("http://localhost:52952/RoomSetting/FirstMeetingRoom.aspx", False)
            Case "Second Meeting Room"
                Response.Redirect("http://localhost:52952/RoomSetting/MainMenu.aspx", False)
        End Select
    End Sub



 <asp:DropDownList ID="DropDownList1" runat="server" Height="20px" AutoPostBack = "true"
        style="margin-top: 0px" Width="404px">
    </asp:DropDownList>



How to fix this? Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: open a window on a page in vwd 2008

Posted 29 July 2010 - 01:25 PM

@nmges: you have to remember that there are two aspects to web development...client side, and server side.

Javascript is a scripting language that is executed client-side in the web browser to modify the user interface by allowing you access to the Document Object Model (DOM) for the elements that make up the page and other things to do with the browser.

VB.NET is a server-side language. It's executed on the server in order to produce HTML that is sent to the browser (this HTML is automatically generated for you based on your logic and the ASP.NET controls you're using).

Each environment is separate and have limited interaction. You can generate Javascript in your VB.NET code so that you can do things in the browser...and you can send information back to the server that is gathered from Javascript using things like hiddenfields or cookies....But, like I said these are executed in completely different environments and so they have limited interaction.

Now, with that in mind, you want to open a new browser window when the user selects something in a DropDownList. You have to use Javascript to open the new browser window (you cannot do this server-side in your VB.NET code).

So what you have to do is write (implement) a Javascript method that opens the window and passes the value selected in the DropDownList via the URL...and you have to call this method when the selected index of the DropDownList changes.


One thing you have to note is that a DropDownList is rendered as an HTML <select> element...it's list items are rendered as HTML <option> elements.


First thing's first, how do you get the value the user selected when the index changes?

Well, you handle the onchange event for the HTML select element.
Here is an example of a simple, static, HTML page that has a <select> element that calls a Javascript method (named "onchangeEventHandler") during it's onchange event. Notice how "this" is passed to the onchangeEventHandler method..."this" refers to the <select> element (like "Me" in VB.NET). If you copy this code into a text document and save the text document as as an .html file it will work:
<html>
<body>
<label for="forumsList">Select a D.I.C forum: </label>
<select onchange="onchangeEventHandler(this)">
  <option value="30-aspnet/">ASP.NET</option>
  <option value="63-web-development/">Web Development</option>
  <option value="67-vbnet/">VB.NET</option>
  <option value="84-c/">C#</option>
</select>

<script type="text/javascript>
  function onchangeEventHandler(selectElement)
  {

    alert('Text Selected: '+ selectElement.options[selectElement.selectedIndex].text);
    alert(' Value Selected: ' + selectElement.options[selectElement.selectedIndex].value);
  }
</script>
 
</body>
</html>



Second, how do you open a new window?
You do this using the window.open method. You pass this method the URL of the page you want to open in the new browser, followed by a name for the new browser, followed by a string containing the parameters for the window (like the width, height, scroll bars etc)

Here is an example of Javascript that opens a new window and displays dream in code:
<html>
<head>
<script type="text/javascript">
function open_win() 
{
    window.open("http://www.dreamincode.net/forums/forum/","DreamInCode","width=850,height=500,scrollbars=yes");
}
</script>
</head>

<body>
<form>
<input type=button value="Open Dream In Code In New Window" onclick="open_win()">
</form>
</body>

</html>


Putting it all together....

Here's Javascript that will open the dream in code forum selected in the <select> element and display it in a new window:
<html>
<body>
<label for="forumsList">Select a D.I.C forum: </label>
<select id='' onchange="onchangeEventHandler(this)">
  <option value=""></option>
  <option value="30-aspnet/">ASP.NET</option>
  <option value="63-web-development/">Web Development</option>
  <option value="67-vbnet/">VB.NET</option>
  <option value="84-c/">C#</option>
</select>

<script type="text/javascript>
  function onchangeEventHandler(selectElement)
  {
    var dreamInCodeForumURL = 'http://www.dreamincode.net/forums/forum/' + selectElement.options[selectElement.selectedIndex].value;
    window.open(dreamInCodeForumURL, 'DreamInCode','width=850,height=500,scrollbars=yes');

  }
</script>
 
</body>
</html>


Now all that's great but how do you apply it to ASP.NET DropDownList? How do you get the DropDOwnList to call the Javascript method during the onchange event?

Well, in your VB.NET code, in your Page Load or Page PreRender add:
If IsPostback = False Then
  myDropDownlist.Attributes.Add("onchange","onchangeEventHandler(this)")
End If


If I were you, I'd remove the AutoPostback from the DropDownList to prevent unnecessary postbacks to the server.

:) There you have it :)

-Frinny

This post has been edited by Frinavale: 29 July 2010 - 01:36 PM

Was This Post Helpful? 2
  • +
  • -

#5 nmges  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-June 10

Re: open a window on a page in vwd 2008

Posted 29 July 2010 - 08:18 PM

Thanks your response, you know there are a lot people to post the answer, the purpose is just to get the reputation scores, and not really understanding the coding program, again thanks your details, I will try to fix this problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1