Execute Hyperlink Programmatically

Discussion in 'ASP .Net' started by Rob Rogers, Sep 21, 2004.

  1. Rob Rogers

    Rob Rogers Guest

    My code creates a dynamic hyperlink from drop down list, and a
    textbox, but has to wait for autopostback to complete for the
    hyperlink to be valid. So is there a way to execute my hyperlink
    programmatically in my "SetState" proc that sets up the hyperlink url.
    I have to have the target frame, so I can't use Response.Redirect.

    Here is my code.

    <%@Page Explicit="True" Language="VB" Debug="True" %>
    <HTML>
    <script runat="server">
    Sub SetState(Sender As Object, E As EventArgs)

    HyperLink1.NavigateUrl = "http://www.natltc.com/search.aspx?St=" &
    JumpTo.SelectedItem.Value & "?City=" & CityBox.text

    End Sub



    </script>
    <body>
    <h1>City &amp; State<BR>
    </h1>
    <form runat="server">
    <P>
    <asp:TextBox id="CityBox" runat="server" autopostback="true"
    OnTextChanged= "SetState"></asp:TextBox><BR>
    Enter City</P>
    <P>&nbsp;</P>
    <P>
    <asp:dropdownlist id="JumpTo" runat="server" autopostback="true"
    OnSelectedIndexChanged="SetState">
    <asp:listitem></asp:listitem>
    <asp:listitem>AL</asp:listitem>
    <asp:listitem>AK</asp:listitem>
    <asp:listitem>AZ</asp:listitem>
    <asp:listitem>TX</asp:listitem>
    <asp:listitem>OK</asp:listitem>

    </asp:dropdownlist><BR>
    Select State</P>
    <P><br>
    <br>
    </ASP:IMAGEBUTTON>
    <asp:HyperLink id="HyperLink1" runat="server" Target="mainFrame"
    NavigateUrl="http://www.natltc.com/search.aspx">HyperLink</asp:HyperLink></P>
    </form>
    </body>
    </HTML>
     
    Rob Rogers, Sep 21, 2004
    #1
    1. Advertising

  2. I dont think you can do that from SetState. But, what you can do is to set a
    hidden field in your SetState().
    And in a client side javascript, create a function which basically uses that
    hidden field to find out if it needs to do a window.open() or a
    window.navigate() to the hyperlink.
    Or, better still, write client side scripts to hook into to those drop down
    selection and text input to construct the hyperlink within client without a
    postback.
    HTH?
    --
    Girish Bharadwaj
    http://msmvps.com/gbvb
    "Rob Rogers" <> wrote in message
    news:...
    > My code creates a dynamic hyperlink from drop down list, and a
    > textbox, but has to wait for autopostback to complete for the
    > hyperlink to be valid. So is there a way to execute my hyperlink
    > programmatically in my "SetState" proc that sets up the hyperlink url.
    > I have to have the target frame, so I can't use Response.Redirect.
    >
    > Here is my code.
    >
    > <%@Page Explicit="True" Language="VB" Debug="True" %>
    > <HTML>
    > <script runat="server">
    > Sub SetState(Sender As Object, E As EventArgs)
    >
    > HyperLink1.NavigateUrl = "http://www.natltc.com/search.aspx?St=" &
    > JumpTo.SelectedItem.Value & "?City=" & CityBox.text
    >
    > End Sub
    >
    >
    >
    > </script>
    > <body>
    > <h1>City &amp; State<BR>
    > </h1>
    > <form runat="server">
    > <P>
    > <asp:TextBox id="CityBox" runat="server" autopostback="true"
    > OnTextChanged= "SetState"></asp:TextBox><BR>
    > Enter City</P>
    > <P>&nbsp;</P>
    > <P>
    > <asp:dropdownlist id="JumpTo" runat="server" autopostback="true"
    > OnSelectedIndexChanged="SetState">
    > <asp:listitem></asp:listitem>
    > <asp:listitem>AL</asp:listitem>
    > <asp:listitem>AK</asp:listitem>
    > <asp:listitem>AZ</asp:listitem>
    > <asp:listitem>TX</asp:listitem>
    > <asp:listitem>OK</asp:listitem>
    >
    > </asp:dropdownlist><BR>
    > Select State</P>
    > <P><br>
    > <br>
    > </ASP:IMAGEBUTTON>
    > <asp:HyperLink id="HyperLink1" runat="server" Target="mainFrame"
    >

    NavigateUrl="http://www.natltc.com/search.aspx">HyperLink</asp:HyperLink></P
    >
    > </form>
    > </body>
    > </HTML>
     
    Girish Bharadwaj, Sep 21, 2004
    #2
    1. Advertising

  3. Rob Rogers

    Shiva Guest

    Other option would be to use client-side JavaScript to dynamically set the
    anchor tag's href.

    Eg:
    <script>
    function changeUrl()
    {
    var dx = window.document.forms[0].ddl;
    ac.href = "http://www.google.com?q=" + dx.options[dx.selectedIndex].text;
    }
    </script>
    <form>
    select id="ddl" onChange="changeUrl();">
    <option>C#</option>
    <option>J#</option>
    </select>
    <a href="#" id="ac" target="mainFrame">Google</a>
    </form>

    Hope this helps.

    "Rob Rogers" <> wrote in message
    news:...
    My code creates a dynamic hyperlink from drop down list, and a
    textbox, but has to wait for autopostback to complete for the
    hyperlink to be valid. So is there a way to execute my hyperlink
    programmatically in my "SetState" proc that sets up the hyperlink url.
    I have to have the target frame, so I can't use Response.Redirect.

    Here is my code.

    <%@Page Explicit="True" Language="VB" Debug="True" %>
    <HTML>
    <script runat="server">
    Sub SetState(Sender As Object, E As EventArgs)

    HyperLink1.NavigateUrl = "http://www.natltc.com/search.aspx?St=" &
    JumpTo.SelectedItem.Value & "?City=" & CityBox.text

    End Sub



    </script>
    <body>
    <h1>City &amp; State<BR>
    </h1>
    <form runat="server">
    <P>
    <asp:TextBox id="CityBox" runat="server" autopostback="true"
    OnTextChanged= "SetState"></asp:TextBox><BR>
    Enter City</P>
    <P>&nbsp;</P>
    <P>
    <asp:dropdownlist id="JumpTo" runat="server" autopostback="true"
    OnSelectedIndexChanged="SetState">
    <asp:listitem></asp:listitem>
    <asp:listitem>AL</asp:listitem>
    <asp:listitem>AK</asp:listitem>
    <asp:listitem>AZ</asp:listitem>
    <asp:listitem>TX</asp:listitem>
    <asp:listitem>OK</asp:listitem>

    </asp:dropdownlist><BR>
    Select State</P>
    <P><br>
    <br>
    </ASP:IMAGEBUTTON>
    <asp:HyperLink id="HyperLink1" runat="server" Target="mainFrame"
    NavigateUrl="http://www.natltc.com/search.aspx">HyperLink</asp:HyperLink></P
    >

    </form>
    </body>
    </HTML>
     
    Shiva, Sep 22, 2004
    #3
    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. TB
    Replies:
    0
    Views:
    509
  2. davetichenor
    Replies:
    1
    Views:
    915
    Eliyahu Goldin
    Oct 30, 2006
  3. Muddy Coder

    How to execute a hyperlink?

    Muddy Coder, Jan 28, 2009, in forum: Python
    Replies:
    6
    Views:
    332
    Jeff McNeil
    Jan 28, 2009
  4. Ken
    Replies:
    1
    Views:
    434
    Alvin Bruney
    Aug 16, 2003
  5. Dave
    Replies:
    0
    Views:
    1,003
Loading...

Share This Page