Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. I need to get the TEXT property of the HyperLink control

I need to get the TEXT property of the HyperLink control

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hurrem
    wrote on last edited by
    #1

    Hello, can somebory tell me how can I get the TEXT property of the HyperLink control like I can get the TEXT property of Textbox, for example: string username = TextBox1.Text; when I'm trying to put Hyperlink1 instead of TextBox1 it gives me exception: System.NullReferenceException: Object reference not set to an instance of an object. Thank you!

    P M 2 Replies Last reply
    0
    • H hurrem

      Hello, can somebory tell me how can I get the TEXT property of the HyperLink control like I can get the TEXT property of Textbox, for example: string username = TextBox1.Text; when I'm trying to put Hyperlink1 instead of TextBox1 it gives me exception: System.NullReferenceException: Object reference not set to an instance of an object. Thank you!

      P Offline
      P Offline
      PrakashBhaskar
      wrote on last edited by
      #2

      you can get the text of hyperlink directly like --> HyperLink1.Text

      Thanks Warm Regards Prakash-B

      H 1 Reply Last reply
      0
      • P PrakashBhaskar

        you can get the text of hyperlink directly like --> HyperLink1.Text

        Thanks Warm Regards Prakash-B

        H Offline
        H Offline
        hurrem
        wrote on last edited by
        #3

        Thanx, but I tried, it gives me an exception, is there any other way?

        H 1 Reply Last reply
        0
        • H hurrem

          Thanx, but I tried, it gives me an exception, is there any other way?

          H Offline
          H Offline
          hurrem
          wrote on last edited by
          #4

          may be it is because I'm using it this way: HyperLink usernameh=(HyperLink) DataList1.FindControl("Hyperlink1"); string username = usernameh.Text;

          P 1 Reply Last reply
          0
          • H hurrem

            Hello, can somebory tell me how can I get the TEXT property of the HyperLink control like I can get the TEXT property of Textbox, for example: string username = TextBox1.Text; when I'm trying to put Hyperlink1 instead of TextBox1 it gives me exception: System.NullReferenceException: Object reference not set to an instance of an object. Thank you!

            M Offline
            M Offline
            Mubashir Javaid
            wrote on last edited by
            #5

            This means that your hyperlink object is not present in ASP XML page. or you have not saved XML page yet. (You have only save code behind page). use this control for hyperlink. LinkButton or use LinkButton

            H 1 Reply Last reply
            0
            • H hurrem

              may be it is because I'm using it this way: HyperLink usernameh=(HyperLink) DataList1.FindControl("Hyperlink1"); string username = usernameh.Text;

              P Offline
              P Offline
              PrakashBhaskar
              wrote on last edited by
              #6

              i do think so coz sometime "DataList1.FindControl("Hyperlink1");" this may return null value if there is no control found. Keep a break point and check wheather your code is returning any controls or not.

              Thanks Warm Regards Prakash-B

              1 Reply Last reply
              0
              • M Mubashir Javaid

                This means that your hyperlink object is not present in ASP XML page. or you have not saved XML page yet. (You have only save code behind page). use this control for hyperlink. LinkButton or use LinkButton

                H Offline
                H Offline
                hurrem
                wrote on last edited by
                #7

                I understand now, it is because there is only one HyperLink1, but the DataList have many rows...

                M 1 Reply Last reply
                0
                • H hurrem

                  I understand now, it is because there is only one HyperLink1, but the DataList have many rows...

                  M Offline
                  M Offline
                  Mubashir Javaid
                  wrote on last edited by
                  #8

                  Datalist is for viewing data. For this purpose you place the hyperlink in gridview and the on RowDataBound event please write. protected void grdMain_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { UploadInfo uploadInfo = new UploadInfo(); LinkButton dr = (LinkButton)e.Row.FindControl("LinkButton1"); } }

                  H 1 Reply Last reply
                  0
                  • M Mubashir Javaid

                    Datalist is for viewing data. For this purpose you place the hyperlink in gridview and the on RowDataBound event please write. protected void grdMain_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { UploadInfo uploadInfo = new UploadInfo(); LinkButton dr = (LinkButton)e.Row.FindControl("LinkButton1"); } }

                    H Offline
                    H Offline
                    hurrem
                    wrote on last edited by
                    #9

                    Thank u very much, but I didn't understand, did u mean Hyperlink instead of Linkbutton? my code used to be like this: protected void btnApprove_Click(object sender, EventArgs e) { HyperLink usernameh=(HyperLink) DataList1.FindControl("Hyperlink1"); string username = HyperLink2.Text; SqlDataSource1.UpdateCommand = "UPDATE Users SET newuser ='" + true + "' WHERE (username='"+username+"')"; SqlDataSource1.Update(); } Thanks!

                    M 1 Reply Last reply
                    0
                    • H hurrem

                      Thank u very much, but I didn't understand, did u mean Hyperlink instead of Linkbutton? my code used to be like this: protected void btnApprove_Click(object sender, EventArgs e) { HyperLink usernameh=(HyperLink) DataList1.FindControl("Hyperlink1"); string username = HyperLink2.Text; SqlDataSource1.UpdateCommand = "UPDATE Users SET newuser ='" + true + "' WHERE (username='"+username+"')"; SqlDataSource1.Update(); } Thanks!

                      M Offline
                      M Offline
                      Mubashir Javaid
                      wrote on last edited by
                      #10

                      HyperLink usernameh=(HyperLink) DataList1.FindControl("Hyperlink1"); this line will not give you the reference of control. Because there can be more rows in the list containing hyperlinks.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups