hyperlink and dynamically formed NavigateURL problem

Discussion in 'ASP .Net' started by Tomek R., Dec 21, 2004.

  1. Tomek R.

    Tomek R. Guest

    Hello !

    This post does'nt regard column hyperlink.
    I just have single hyperlink and want to create it's NavigateUrl
    dynamically.

    This is my test page

    <form id="Form1" method="post" runat="server">
    <asp:HyperLink id="MyHLink" NavigateUrl='<%# geturl("123456") %>'
    style="Z-INDEX: 101; LEFT: 280px; POSITION: absolute; TOP: 56px"
    runat="server" >MyHLink</asp:HyperLink>
    </form>

    and my class behind

    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.HyperLink MyHLink;
    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    //this.MyHLink.NavigateUrl = MyString();
    }
    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    InitializeComponent();
    base.OnInit(e);
    }

    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);
    }
    #endregion
    protected string geturl(string s)
    { return "www.mypage.com "+s; }
    }

    Resulting page includes hyperlink, but inactive - not href tag attached. The
    syntax is O'K, I believe (no errors on page load).
    I've spent a couple of hours for browsing the newsgroups but haven't find
    working solution for HTML designing.
    What means, I can do this but only when setting NavigateUrl in Page_Load
    like this:

    private void Page_Load(object sender, System.EventArgs e)
    {
    MyHLink.NavigateUrl = geturl("123456");
    }

    No matter what kind of Url I put (absolute, relative) - Page_Load works
    every time.

    The only reason I can think about, is that one: geturl and class-behind is
    not accessible, when hyperlink is rendered based on design values.
    Am I right ?
    If yes, how about datagrid and TemplateItem column with hyperlink. In that
    case settings like above work perfectly. What is the differences between
    datagrid column and hyperlink on page ?

    Regards,

    --
    Tomek R.
     
    Tomek R., Dec 21, 2004
    #1
    1. Advertising

  2. Tomek R.

    Karl Seguin Guest

    instead of doing NavigateUrl='<%# geturl("12345")%>' do NavigateUrl='<%=
    getUrl("12345")%>'

    <%# is for databinding, you aren'd databinding and therefore need touse <%=

    doing it form your Page_Load, ala:
    MyHLink.NavigateUrl = geturl("123456");

    should work (And is how you should do it, no clumsy method calls in your
    presentation), but if you still had the <%# in there, dunno how that would
    behave...

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Tomek R." <> wrote in message
    news:...
    > Hello !
    >
    > This post does'nt regard column hyperlink.
    > I just have single hyperlink and want to create it's NavigateUrl
    > dynamically.
    >
    > This is my test page
    >
    > <form id="Form1" method="post" runat="server">
    > <asp:HyperLink id="MyHLink" NavigateUrl='<%# geturl("123456") %>'
    > style="Z-INDEX: 101; LEFT: 280px; POSITION: absolute; TOP: 56px"
    > runat="server" >MyHLink</asp:HyperLink>
    > </form>
    >
    > and my class behind
    >
    > public class WebForm1 : System.Web.UI.Page
    > {
    > protected System.Web.UI.WebControls.HyperLink MyHLink;
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > // Put user code to initialize the page here
    > //this.MyHLink.NavigateUrl = MyString();
    > }
    > #region Web Form Designer generated code
    > override protected void OnInit(EventArgs e)
    > {
    > InitializeComponent();
    > base.OnInit(e);
    > }
    >
    > private void InitializeComponent()
    > {
    > this.Load += new System.EventHandler(this.Page_Load);
    > }
    > #endregion
    > protected string geturl(string s)
    > { return "www.mypage.com "+s; }
    > }
    >
    > Resulting page includes hyperlink, but inactive - not href tag attached.

    The
    > syntax is O'K, I believe (no errors on page load).
    > I've spent a couple of hours for browsing the newsgroups but haven't find
    > working solution for HTML designing.
    > What means, I can do this but only when setting NavigateUrl in Page_Load
    > like this:
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > MyHLink.NavigateUrl = geturl("123456");
    > }
    >
    > No matter what kind of Url I put (absolute, relative) - Page_Load works
    > every time.
    >
    > The only reason I can think about, is that one: geturl and class-behind is
    > not accessible, when hyperlink is rendered based on design values.
    > Am I right ?
    > If yes, how about datagrid and TemplateItem column with hyperlink. In that
    > case settings like above work perfectly. What is the differences between
    > datagrid column and hyperlink on page ?
    >
    > Regards,
    >
    > --
    > Tomek R.
    >
    >
     
    Karl Seguin, Dec 21, 2004
    #2
    1. Advertising

  3. Tomek R.

    Tomek R. Guest

    Karl !
    Thanks for reply.

    > <%# is for databinding, you aren'd databinding and therefore need touse

    <%=
    Yeah, I found some posts with this info, but <%= doesn't work. The resulting
    link is the whole phrase, inlcuding <% .

    --
    Tomek R.
     
    Tomek R., Dec 21, 2004
    #3
  4. Tomek R.

    Karl Seguin Guest

    Ya, was being an idiot when I just woke up :)

    The correct way to go, as I originally said, is via the Page_Load and doing
    MyHLink.NavigateUrl = geturl("123456");

    if you are certain Page_Load is running, and you don' thave NavigateUrl set
    to anything in the HTML (don't even specifiy the problem), it should work.

    karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Tomek R." <> wrote in message
    news:%...
    > Karl !
    > Thanks for reply.
    >
    > > <%# is for databinding, you aren'd databinding and therefore need touse

    > <%=
    > Yeah, I found some posts with this info, but <%= doesn't work. The

    resulting
    > link is the whole phrase, inlcuding <% .
    >
    > --
    > Tomek R.
    >
    >
     
    Karl Seguin, Dec 21, 2004
    #4
  5. Tomek R.

    Tomek R. Guest

    Karl !

    Thanks for reply.

    --
    Tomek R.
     
    Tomek R., Dec 27, 2004
    #5
  6. Tomek R.

    csobha

    Joined:
    May 28, 2008
    Messages:
    2
    do you still have the isue

    Hi,
    I have the same issue...is it the only way to load it on page load
     
    csobha, May 28, 2008
    #6
  7. Tomek R.

    csobha

    Joined:
    May 28, 2008
    Messages:
    2
    I have the same issue...is it the only way to load it on page load
     
    csobha, May 28, 2008
    #7
  8. Tomek R.

    Sobot

    Joined:
    Feb 13, 2009
    Messages:
    3
    Location:
    Belgrade
    For the problem of absolute url binding to NavigateURL field of asp:HyperLink
    Solution is to use Page_PreRender method to do the binding because it will be overwritten if you do it Page_OnLoad

    can find more here
    asp:HyperLink NavigateUrl Problem Absolute URL

    Link: sobot-software.blogspot.com/2009/02/asphyperlink-navigateurl-problem.html

    Sobot Software DotNetNuke Outsourcing
     
    Sobot, Feb 13, 2009
    #8
    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. Boban Dragojlovic
    Replies:
    3
    Views:
    3,048
    vMike
    Oct 29, 2003
  2. Mark Fox

    Hyperlink NavigateUrl

    Mark Fox, Nov 3, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    9,325
    Mark Fox
    Nov 4, 2003
  3. VB Programmer
    Replies:
    3
    Views:
    10,644
    VB Programmer
    Nov 16, 2005
  4. gerry

    asp:Hyperlink NavigateUrl problem

    gerry, Jan 18, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    8,609
    Sobot
    Feb 13, 2009
  5. Christoph Schuster

    Problem with Hyperlink.NavigateURL="../../" in WebControls

    Christoph Schuster, Jul 21, 2003, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    290
    Yan-Hong Huang[MSFT]
    Jul 23, 2003
Loading...

Share This Page