• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • 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
 
informaniacCommented:
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
 
informaniacCommented:
HyperLink _lala = (HyperLink)DetailsView1.Rows[DetailsView1.DataItemIndex].FindControl("lala");
            _lala.Text = "hello";
0
 
sqlnoobAuthor Commented:
hi informaniac,

it is not working :(
0
 
informaniacCommented:
<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

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

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