I need to get the TEXT property of the HyperLink control
-
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!
-
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!
you can get the text of hyperlink directly like --> HyperLink1.Text
Thanks Warm Regards Prakash-B
-
you can get the text of hyperlink directly like --> HyperLink1.Text
Thanks Warm Regards Prakash-B
-
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!
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
-
may be it is because I'm using it this way:
HyperLink usernameh=(HyperLink) DataList1.FindControl("Hyperlink1"); string username = usernameh.Text;
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
-
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
-
I understand now, it is because there is only one HyperLink1, but the DataList have many rows...
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"); } }
-
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"); } }
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! -
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!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.