• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

C#, How do you put a hyperlink tag inside a control and still refer it in the code?

<asp:DetailsView>
<asp:HyperLink ID="lala" runat="server"></asp:HyperLink>
</asp:DetailsView>
lala.Text="hello"; // works


<EmptyDataTemplate><asp:HyperLink ID="lala" runat="server"></asp:HyperLink></EmptyDataTemplate>
lala.Text="hi"; // don't work, Error      100      The name 'lala' does not exist in the current context

already tried:
HyperLink _lala = (HyperLink)DetailsView1.FindControl("lala");
_lala.Text = "hello"

but it complies but the value is empty also when I try: _lala.NavigateUrl = "http://www.yahoo.com";
the url in the html is blank. I think it is only setting the copy's value not the original's value
0
sqlnoob
Asked:
sqlnoob
  • 3
  • 2
1 Solution
 
Obadiah ChristopherCommented:
You'll have to handle the detailsview ItemCreated event and place

HyperLink _lala = (HyperLink)DetailsView1.FindControl("lala");
_lala.Text = "hello";

inside the DetailsView1_ItemCreated event

like this...
protected void DetailsView1_ItemCreated(object sender, EventArgs e)
{
            HyperLink _lala = (HyperLink)DetailsView1.FindControl("lala");
            _lala.Text = "hello";
}

Open in new window

0
 
sqlnoobAuthor Commented:
nope don't work :(


  protected void x_ItemCreated(object sender, DetailsViewPageEventArgs e)
  {
          HyperLink t1 = (HyperLink)x.FindControl("testlink");
          t1.Text = "yahoo";
          t1.NavigateUrl = "yahoo.com";

  }

<a id="ctl00_ContentPlaceHolder1_x_testlink">click me</a>
0
 
Obadiah ChristopherCommented:
HyperLink _lala = (HyperLink)DetailsView1.Rows[DetailsView1.DataItemIndex].FindControl("lala");
            _lala.Text = "hello";
0
 
sqlnoobAuthor Commented:
hi informaniac,

it is not working :(
0
 
Obadiah ChristopherCommented:
<asp:DetailsView>
<asp:HyperLink ID="lala" runat="server"></asp:HyperLink>
</asp:DetailsView>

Is this what u've written or is there something in between that you haven't posted.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now