Dim PeerAllow As New System.Data.SqlClient.SqlCommand(("Select user_full_name From dbo.QryUser WHERE UserName=@UserName"), conn)
PeerAllow.Parameters.AddWithValue("@UserName", User.Identity.Name)
Using Autoreader As System.Data.SqlClient.SqlDataReader = PeerAllow.ExecuteReader()
While Autoreader.Read()
Dim user_full_name As String = Autoreader.GetValue(0)
If user_full_name = txtUATauthor.Text Then
LinkButton5.Enabled = False
End If
If user_full_name = cmbpeername1.SelectedItem.Text Then
LinkButton3.Enabled = False
LinkButton4.Enabled = False
LinkButton5.Enabled = False
End If
Even if the username is the same - the LinkButton5 enabled is set to False when username = txtUATauthor.Text but for cmbpeername1.SelectedItem.Text even
if it appears the same as username.. it still doesnt disabled the LinkButtons3, 4 & 5 .. Why???
This is called on PageLoad anmd it appears it doesnt recognise the combo box value however it reads the textbox OK..
1) make sure you have some IF NOT IsPostback checks
2) you only ever set LinkButton5.Enabled = False. I'd recommend doing some ELSE options to set to TRUE
Additionally, be careful with 2 differernt IF statements setting the same control, it can get rough.
Additionally, I usually recommend you do some .Trim.ToLower on the strings if you are going to do a comparison.
Have you read the book? - ASP.Net 3.5 CMS Development (now on Kindle)
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
Also be aware that text comparisons tend to be case sensitive so "hello" is not the same as "Hello". If you don't need them to be case sensitive then you can call the ToLower() method on each like:
If user_full_name.ToLower() = txtUATauthor.Text.ToLower() Then
or
If user_full_name.Equals(txtUITauthor.Text,StringComparison.InvariantCultureIgnoreCase) Then
Don't forget to mark useful responses as Answer if they helped you towards a solution.
dr223
Member
8 Points
336 Posts
On Page Load Textbox works - Combo Box doesnt work!!
Feb 26, 2013 02:54 PM|LINK
Hi,
I have the following code;
Dim PeerAllow As New System.Data.SqlClient.SqlCommand(("Select user_full_name From dbo.QryUser WHERE UserName=@UserName"), conn) PeerAllow.Parameters.AddWithValue("@UserName", User.Identity.Name) Using Autoreader As System.Data.SqlClient.SqlDataReader = PeerAllow.ExecuteReader() While Autoreader.Read() Dim user_full_name As String = Autoreader.GetValue(0) If user_full_name = txtUATauthor.Text Then LinkButton5.Enabled = False End If If user_full_name = cmbpeername1.SelectedItem.Text Then LinkButton3.Enabled = False LinkButton4.Enabled = False LinkButton5.Enabled = False End IfAt this point assuming user_full_name =
Curt_C
All-Star
66017 Points
7639 Posts
Moderator
Re: On Page Load Textbox works - Combo Box doesnt work!!
Feb 26, 2013 03:06 PM|LINK
1) make sure you have some IF NOT IsPostback checks
2) you only ever set LinkButton5.Enabled = False. I'd recommend doing some ELSE options to set to TRUE
Additionally, be careful with 2 differernt IF statements setting the same control, it can get rough.
Additionally, I usually recommend you do some .Trim.ToLower on the strings if you are going to do a comparison.
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
dr223
Member
8 Points
336 Posts
Re: On Page Load Textbox works - Combo Box doesnt work!!
Feb 26, 2013 03:22 PM|LINK
I think this is what I need but I dont know to implement it ..
Any help please
Thanks
Curt_C
All-Star
66017 Points
7639 Posts
Moderator
Re: On Page Load Textbox works - Combo Box doesnt work!!
Feb 26, 2013 07:20 PM|LINK
Sub Page_Load()
If Not IsPostback Then
....your code.....
End If
End Sub
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
markfitzme
Star
14491 Points
2241 Posts
Re: On Page Load Textbox works - Combo Box doesnt work!!
Feb 27, 2013 04:13 AM|LINK
Also be aware that text comparisons tend to be case sensitive so "hello" is not the same as "Hello". If you don't need them to be case sensitive then you can call the ToLower() method on each like: If user_full_name.ToLower() = txtUATauthor.Text.ToLower() Then
or
If user_full_name.Equals(txtUITauthor.Text,StringComparison.InvariantCultureIgnoreCase) Then