Open new browser window in vbscript.net

Discussion in 'ASP .Net' started by smokeyd, Dec 21, 2006.

  1. smokeyd

    smokeyd Guest

    hi,

    can anyone tell me how to open a link in a new browser window in
    vbscript.net. i am looking to be able to set the properties such as
    size, menu bar, scroll bar etc. or alternativelly is there a simple
    way to do this in visual web developer?

    many thanks in advance for your help.
    smokeyd, Dec 21, 2006
    #1
    1. Advertising

  2. Heres an example aspx page for you that shows you how to do it in vb.net.
    This works in VWD.

    <script runat="server">
    Sub Page_Load( sender as Object,e as EventArgs)

    Dim scriptString As String
    scriptString = "<script language=JavaScript> function DoClick() {"
    scriptString +=
    "window.open('http://www.mvps.org','MyWindow','width=500,height=500');}<"
    scriptString += "/"
    scriptString += "script>"

    If (Not ClientScript.IsClientScriptBlockRegistered("ClientScript"))
    Then
    ClientScript.RegisterClientScriptBlock(Me.GetType(),
    "ClientScript", scriptString)
    End If

    End Sub

    </script>

    <html>
    <body topmargin="20" leftmargin="10">
    <form id="myForm" runat="server">
    <input type="button" value="ClickMe" onclick="DoClick()">
    </form>
    </body>
    </html>

    --
    --
    Regards

    John Timney (MVP)
    VISIT MY WEBSITE:
    http://www.johntimney.com
    http://www.johntimney.com/blog


    "smokeyd" <> wrote in message
    news:...
    > hi,
    >
    > can anyone tell me how to open a link in a new browser window in
    > vbscript.net. i am looking to be able to set the properties such as
    > size, menu bar, scroll bar etc. or alternativelly is there a simple
    > way to do this in visual web developer?
    >
    > many thanks in advance for your help.
    >
    John Timney \(MVP\), Dec 21, 2006
    #2
    1. Advertising

  3. smokeyd

    Mark Rae Guest

    "John Timney (MVP)" <> wrote in message
    news:...

    Hi John,

    > scriptString = "<script language=JavaScript> function DoClick() {"


    That syntax is deprecated now, and won't produce XHTML-compliant markup.

    Use this instead:

    scriptString = "<script type=\"text/javascript\"> function DoClick() {"

    Mark

    P.S. Not a problem if you don't need cross-browser compatibility... ;-)
    Mark Rae, Dec 21, 2006
    #3
  4. fair comment.....I'll change the source example so next time I post it its
    covered :)
    --
    Regards

    John Timney (MVP)
    http://www.johntimney.com
    http://www.johntimney.com/blog


    "Mark Rae" <> wrote in message
    news:...
    > "John Timney (MVP)" <> wrote in message
    > news:...
    >
    > Hi John,
    >
    >> scriptString = "<script language=JavaScript> function DoClick() {"

    >
    > That syntax is deprecated now, and won't produce XHTML-compliant markup.
    >
    > Use this instead:
    >
    > scriptString = "<script type=\"text/javascript\"> function DoClick() {"
    >
    > Mark
    >
    > P.S. Not a problem if you don't need cross-browser compatibility... ;-)
    >
    John Timney \(MVP\), Dec 21, 2006
    #4
  5. Just for clarity in the thread - for VB.NET the code is
    scriptString = "<script type=""text/javascript""> function DoClick() {"

    Full example below:
    --
    Regards

    John Timney (MVP)
    VISIT MY WEBSITE:
    http://www.johntimney.com
    http://www.johntimney.com/blog

    <%@ Page Language="VB" %>
    <script runat="server">
    Sub Page_Load( sender as Object,e as EventArgs)
    Dim scriptString As String
    scriptString = "<script type=""text/javascript""> function DoClick()
    {"
    scriptString +=
    "window.open('http://www.mvps.org','MyWindow','width=500,height=500');}<"
    scriptString += "/"
    scriptString += "script>"

    If (Not ClientScript.IsClientScriptBlockRegistered("ClientScript"))
    Then
    ClientScript.RegisterClientScriptBlock(Me.GetType(),
    "ClientScript", scriptString)
    End If
    End Sub
    </script>

    <html>
    <body topmargin="20" leftmargin="10">
    <form id="myForm" runat="server">
    <input type="button" value="ClickMe" onclick="DoClick()">
    </form>
    </body>
    </html>

    "John Timney (MVP)" <> wrote in message
    news:...
    > fair comment.....I'll change the source example so next time I post it its
    > covered :)
    > --
    > Regards
    >
    > John Timney (MVP)
    > http://www.johntimney.com
    > http://www.johntimney.com/blog
    >
    >
    > "Mark Rae" <> wrote in message
    > news:...
    >> "John Timney (MVP)" <> wrote in message
    >> news:...
    >>
    >> Hi John,
    >>
    >>> scriptString = "<script language=JavaScript> function DoClick()
    >>> {"

    >>
    >> That syntax is deprecated now, and won't produce XHTML-compliant markup.
    >>
    >> Use this instead:
    >>
    >> scriptString = "<script type=\"text/javascript\"> function DoClick() {"
    >>
    >> Mark
    >>
    >> P.S. Not a problem if you don't need cross-browser compatibility... ;-)
    >>

    >
    >
    John Timney \(MVP\), Dec 21, 2006
    #5
  6. smokeyd

    smokeyd Guest

    John Timney (MVP) wrote:

    > Just for clarity in the thread - for VB.NET the code is
    > scriptString = "<script type=""text/javascript""> function DoClick() {"
    >
    > Full example below:
    > --
    > Regards
    >
    > John Timney (MVP)
    > VISIT MY WEBSITE:
    > http://www.johntimney.com
    > http://www.johntimney.com/blog
    >
    > <%@ Page Language="VB" %>
    > <script runat="server">
    > Sub Page_Load( sender as Object,e as EventArgs)
    > Dim scriptString As String
    > scriptString = "<script type=""text/javascript""> function DoClick()
    > {"
    > scriptString +=
    > "window.open('http://www.mvps.org','MyWindow','width=500,height=500');}<"
    > scriptString += "/"
    > scriptString += "script>"
    >
    > If (Not ClientScript.IsClientScriptBlockRegistered("ClientScript"))
    > Then
    > ClientScript.RegisterClientScriptBlock(Me.GetType(),
    > "ClientScript", scriptString)
    > End If
    > End Sub
    > </script>
    >
    > <html>
    > <body topmargin="20" leftmargin="10">
    > <form id="myForm" runat="server">
    > <input type="button" value="ClickMe" onclick="DoClick()">
    > </form>
    > </body>
    > </html>
    >
    > "John Timney (MVP)" <> wrote in message
    > news:...
    > > fair comment.....I'll change the source example so next time I post it its
    > > covered :)
    > > --
    > > Regards
    > >
    > > John Timney (MVP)
    > > http://www.johntimney.com
    > > http://www.johntimney.com/blog
    > >
    > >
    > > "Mark Rae" <> wrote in message
    > > news:...
    > >> "John Timney (MVP)" <> wrote in message
    > >> news:...
    > >>
    > >> Hi John,
    > >>
    > >>> scriptString = "<script language=JavaScript> function DoClick()
    > >>> {"
    > >>
    > >> That syntax is deprecated now, and won't produce XHTML-compliant markup.
    > >>
    > >> Use this instead:
    > >>
    > >> scriptString = "<script type=\"text/javascript\"> function DoClick() {"
    > >>
    > >> Mark
    > >>
    > >> P.S. Not a problem if you don't need cross-browser compatibility... ;-)
    > >>

    > >
    > >


    thanks for all of the help. the code needed a few little tweaks but
    works great:

    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim scriptString As String
    scriptString = "<script type=""text/javascript""> function
    DoClick() {"
    scriptString +=
    "window.open('popup.aspx','MyWindow','width=500,height=500');}<"
    scriptString += "/"
    scriptString += "script>"
    If (Not
    ClientScript.IsClientScriptBlockRegistered("ClientScript")) Then
    ClientScript.RegisterClientScriptBlock(Me.GetType(),
    "ClientScript", scriptString)
    End If
    End Sub
    </script>


    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:HyperLink ID="HyperLink1" runat="server"
    OnClick="DoClick()" NavigateUrl="#"> HyperLink</asp:HyperLink></div>
    </form>
    </body>
    </html>

    however visual web developer gives an error saying onclick is not a
    valid attribute of element 'hyperlink' but seems to work okay anyway..
    smokeyd, Dec 21, 2006
    #6
  7. smokeyd

    Jon Paal Guest

    http://www.dotnetjohn.com/articles.aspx?articleid=88





    "smokeyd" <> wrote in message news:...
    > hi,
    >
    > can anyone tell me how to open a link in a new browser window in
    > vbscript.net. i am looking to be able to set the properties such as
    > size, menu bar, scroll bar etc. or alternativelly is there a simple
    > way to do this in visual web developer?
    >
    > many thanks in advance for your help.
    >
    Jon Paal, Dec 21, 2006
    #7
  8. Change your hyperlink declaration to:

    <asp:HyperLink ID="HyperLink1" runat="server"
    NavigateUrl="javascript:DoClick()"> HyperLink</asp:HyperLink>

    and your warning should go away.....
    Regards


    John Timney (MVP)
    VISIT MY WEBSITE:
    http://www.johntimney.com
    http://www.johntimney.com/blog


    "smokeyd" <> wrote in message
    news:...
    >
    > John Timney (MVP) wrote:
    >
    >> Just for clarity in the thread - for VB.NET the code is
    >> scriptString = "<script type=""text/javascript""> function DoClick() {"
    >>
    >> Full example below:
    >> --
    >> Regards
    >>
    >> John Timney (MVP)
    >> VISIT MY WEBSITE:
    >> http://www.johntimney.com
    >> http://www.johntimney.com/blog
    >>
    >> <%@ Page Language="VB" %>
    >> <script runat="server">
    >> Sub Page_Load( sender as Object,e as EventArgs)
    >> Dim scriptString As String
    >> scriptString = "<script type=""text/javascript""> function
    >> DoClick()
    >> {"
    >> scriptString +=
    >> "window.open('http://www.mvps.org','MyWindow','width=500,height=500');}<"
    >> scriptString += "/"
    >> scriptString += "script>"
    >>
    >> If (Not
    >> ClientScript.IsClientScriptBlockRegistered("ClientScript"))
    >> Then
    >> ClientScript.RegisterClientScriptBlock(Me.GetType(),
    >> "ClientScript", scriptString)
    >> End If
    >> End Sub
    >> </script>
    >>
    >> <html>
    >> <body topmargin="20" leftmargin="10">
    >> <form id="myForm" runat="server">
    >> <input type="button" value="ClickMe" onclick="DoClick()">
    >> </form>
    >> </body>
    >> </html>
    >>
    >> "John Timney (MVP)" <> wrote in message
    >> news:...
    >> > fair comment.....I'll change the source example so next time I post it
    >> > its
    >> > covered :)
    >> > --
    >> > Regards
    >> >
    >> > John Timney (MVP)
    >> > http://www.johntimney.com
    >> > http://www.johntimney.com/blog
    >> >
    >> >
    >> > "Mark Rae" <> wrote in message
    >> > news:...
    >> >> "John Timney (MVP)" <> wrote in message
    >> >> news:...
    >> >>
    >> >> Hi John,
    >> >>
    >> >>> scriptString = "<script language=JavaScript> function
    >> >>> DoClick()
    >> >>> {"
    >> >>
    >> >> That syntax is deprecated now, and won't produce XHTML-compliant
    >> >> markup.
    >> >>
    >> >> Use this instead:
    >> >>
    >> >> scriptString = "<script type=\"text/javascript\"> function DoClick()
    >> >> {"
    >> >>
    >> >> Mark
    >> >>
    >> >> P.S. Not a problem if you don't need cross-browser compatibility...
    >> >> ;-)
    >> >>
    >> >
    >> >

    >
    > thanks for all of the help. the code needed a few little tweaks but
    > works great:
    >
    > <%@ Page Language="VB" %>
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <script runat="server">
    > Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    > Dim scriptString As String
    > scriptString = "<script type=""text/javascript""> function
    > DoClick() {"
    > scriptString +=
    > "window.open('popup.aspx','MyWindow','width=500,height=500');}<"
    > scriptString += "/"
    > scriptString += "script>"
    > If (Not
    > ClientScript.IsClientScriptBlockRegistered("ClientScript")) Then
    > ClientScript.RegisterClientScriptBlock(Me.GetType(),
    > "ClientScript", scriptString)
    > End If
    > End Sub
    > </script>
    >
    >
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    > <head runat="server">
    > <title>Untitled Page</title>
    > </head>
    > <body>
    > <form id="form1" runat="server">
    > <div>
    > <asp:HyperLink ID="HyperLink1" runat="server"
    > OnClick="DoClick()" NavigateUrl="#"> HyperLink</asp:HyperLink></div>
    > </form>
    > </body>
    > </html>
    >
    > however visual web developer gives an error saying onclick is not a
    > valid attribute of element 'hyperlink' but seems to work okay anyway..
    >
    John Timney \(MVP\), Dec 21, 2006
    #8
  9. John Timney (MVP) wrote:
    >>Change your hyperlink declaration to:
    >><asp:HyperLink ID="HyperLink1" runat="server"
    >>NavigateUrl="javascript:DoClick()"> HyperLink</asp:HyperLink>



    or..... if you want to use the onlclick event in page_load add this:

    HyperLink1.attributes.add("onclick", "DoClick()")

    Alexander Higgins
    http://www.affordablewebdesignsinc.com
    Alexander Higgins, Dec 21, 2006
    #9
  10. Yes, you can do that of course.

    The hyperlink declaration should be changed to:

    <asp:HyperLink ID="HyperLink1" NavigateUrl="#" runat="server" >
    HyperLink</asp:HyperLink>

    A quirk with using attributes.add - If you dont set the NavigateUrl property
    and dont style it you will get a plain old clickable word.

    Regards

    John Timney (MVP)
    VISIT MY WEBSITE:
    http://www.johntimney.com
    http://www.johntimney.com/blog


    "Alexander Higgins" <> wrote in message
    news:...
    > John Timney (MVP) wrote:
    >>>Change your hyperlink declaration to:
    >>><asp:HyperLink ID="HyperLink1" runat="server"
    >>>NavigateUrl="javascript:DoClick()"> HyperLink</asp:HyperLink>

    >
    >
    > or..... if you want to use the onlclick event in page_load add this:
    >
    > HyperLink1.attributes.add("onclick", "DoClick()")
    >
    > Alexander Higgins
    > http://www.affordablewebdesignsinc.com
    >
    John Timney \(MVP\), Dec 22, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Tm92aWNl?=
    Replies:
    2
    Views:
    6,618
    Alan Ferrandiz Langley
    Jun 9, 2004
  2. Shiperton Henethe
    Replies:
    17
    Views:
    5,356
    Deirdre Saoirse Moen
    May 21, 2004
  3. Gordon
    Replies:
    3
    Views:
    286
    Steven Burn
    Apr 16, 2004
  4. raj
    Replies:
    0
    Views:
    184
  5. PC HUA
    Replies:
    2
    Views:
    392
    PC HUA
    May 19, 2004
Loading...

Share This Page