creating a dynamic link in ASP.NET.....how??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    creating a dynamic link in ASP.NET.....how??

    I have been struggling in learning .NET. I have the datagrid and repeater controls figured out, and using readers, etc.

    However, I've been trying to write out a link and use a variable as one of the parameters of the querystring as I used to in classic ASP. For example:
    <a href=mypage.asp ?n=" & MyParameter & ">Link</a>

    How can I duplicate this functionality in ASP.NET pages???

    I have tried using the link1.HRef="htt p://www.mypage.com? n=" & MyParameter & ""

    Then printing the link on the page using the <a id="link1" runat="server">

    However, the compiler doesn't seem to want to convert it and I keep getting errors. Any help would be appreciated....
    Thanks
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    OK I have also tried using session variables for this, with no luck.....very frustrating as it seems like this should be a simple task!

    Compiler Error Message: BC30203: Identifier expected.

    Source Error:

    Line 34: Sub profilelink(sen der As Object, e As EventArgs)
    Line 35: dim CName
    Line 36: CName = Session["Character"].ToString();
    Line 37: response.Redire ct("Scharacter. aspx?n=" & CName & "")
    Line 38: End Sub

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      did try hyperlink in datagrid or repeater ??
      Or
      U have one link, and u want assign source dynamically

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        What would be even more frustrating would be to get stuck on this kind of basic problem again. That is why you need to learn the basics from a course, tutorial or book. My advice is do the hard yards now and it will pay off later. Who knows you may become an expert on this forum?

        Comment

        • jeffstl
          Recognized Expert Contributor
          • Feb 2008
          • 432

          #5
          Actually I found a solution but Im not sure its a good one. I am using a literal control to print out the link.

          In answer to the above question it is just a single link I am trying to print, not a table of links.

          Here is what I did:
          profilelink.Tex t = "<a href=Spage.aspx ?n=" & server.UrlEncod e(MyParameter) & ">Profile</a>"

          Then in the page:
          <asp:Literal id="profilelink " runat="server" />


          Please let me know if this is an ok solution?
          Thanks
          Jeff

          Comment

          • kunal pawar
            Contributor
            • Oct 2007
            • 297

            #6
            u r modified code

            profilelink.Tex t = "<a href=Spage.aspx ?n='" & server.UrlEncod e(MyParameter) & "'>Profile</a>"

            Or best way to use server control i.e. Hyperlink control

            Comment

            Working...