Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > hyperlink and dynamically formed NavigateURL problem

Reply
Thread Tools

hyperlink and dynamically formed NavigateURL problem

 
 
Tomek R.
Guest
Posts: n/a
 
      12-21-2004
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.


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      12-21-2004
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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
 
 
 
Tomek R.
Guest
Posts: n/a
 
      12-21-2004
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.


 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      12-21-2004
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." <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Tomek R.
Guest
Posts: n/a
 
      12-27-2004
Karl !

Thanks for reply.

--
Tomek R.


 
Reply With Quote
 
csobha csobha is offline
Junior Member
Join Date: May 2008
Posts: 2
 
      05-28-2008
Hi,
I have the same issue...is it the only way to load it on page load
 
Reply With Quote
 
csobha csobha is offline
Junior Member
Join Date: May 2008
Posts: 2
 
      05-28-2008
I have the same issue...is it the only way to load it on page load
 
Reply With Quote
 
Sobot Sobot is offline
Junior Member
Join Date: Feb 2009
Location: Belgrade
Posts: 3
 
      02-13-2009
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp:Hyperlink NavigateUrl problem gerry ASP .Net 3 02-13-2009 05:02 PM
Problem setting NavigateUrl's in DataList (hyperlink) VB Programmer ASP .Net 3 11-16-2005 12:29 AM
Hyperlink NavigateUrl Mark Fox ASP .Net 5 11-04-2003 08:21 AM
undesired behavior in setting hyperlink .NavigateURL property Boban Dragojlovic ASP .Net 3 10-29-2003 09:05 PM
Problem with Hyperlink.NavigateURL="../../" in WebControls Christoph Schuster ASP .Net Web Controls 4 07-23-2003 09:05 AM



Advertisments