Get text in a textbox
-
Good morning every body! Please help me out in this since I can't really figure out what is wrong. I have a datalist control that displays posted status. Inside this datalist is a textbox control and a button 'Add idea'. I want visitors to add their own idea so I used this code
Public Sub AddIdea(ByVal sender As Object, e As DataListEventsCommand...)
Dim txt As TextBox = e.Item.FindControl("txtidea")
If txt.Text <> "" Then
MsgBox (txt.Text)
Else
MsgBox ("No idea entered")
End SubBut if the Add idea button is heat, the msgbox returns an empty string. Help please.
-
Good morning every body! Please help me out in this since I can't really figure out what is wrong. I have a datalist control that displays posted status. Inside this datalist is a textbox control and a button 'Add idea'. I want visitors to add their own idea so I used this code
Public Sub AddIdea(ByVal sender As Object, e As DataListEventsCommand...)
Dim txt As TextBox = e.Item.FindControl("txtidea")
If txt.Text <> "" Then
MsgBox (txt.Text)
Else
MsgBox ("No idea entered")
End SubBut if the Add idea button is heat, the msgbox returns an empty string. Help please.
Debug your code and check what is the value you are getting in
txt
variable. It looks liketxtidea
control is not found byFindControl()
and hence the result is empty. Also, avoid checking string values with ""If txt.Text <> "" Then
Instead use
If !string.IsNullOrEmpty(txt.Text) Then
its cleaner and less error prone.
-
Debug your code and check what is the value you are getting in
txt
variable. It looks liketxtidea
control is not found byFindControl()
and hence the result is empty. Also, avoid checking string values with ""If txt.Text <> "" Then
Instead use
If !string.IsNullOrEmpty(txt.Text) Then
its cleaner and less error prone.
Abhipal Singh wrote:
If **!**string.IsNullOrEmpty(...
VB.NET uses
Not
, not!
, for logical negation. :)
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Good morning every body! Please help me out in this since I can't really figure out what is wrong. I have a datalist control that displays posted status. Inside this datalist is a textbox control and a button 'Add idea'. I want visitors to add their own idea so I used this code
Public Sub AddIdea(ByVal sender As Object, e As DataListEventsCommand...)
Dim txt As TextBox = e.Item.FindControl("txtidea")
If txt.Text <> "" Then
MsgBox (txt.Text)
Else
MsgBox ("No idea entered")
End SubBut if the Add idea button is heat, the msgbox returns an empty string. Help please.
MsgBox
isn't going to work in an ASP.NET application. The message will be displayed on the server, not the client. It might appear to work when you debug your code in Visual Studio, but that's only because the server and the client are the same machine in that specific scenario. As soon as you deploy your code to a real server, it will either crash, or hang waiting for someone to acknowledge the message on the server, where nobody will ever see it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Abhipal Singh wrote:
If **!**string.IsNullOrEmpty(...
VB.NET uses
Not
, not!
, for logical negation. :)
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thanks for correcting me Richard! I generally work on C# so, not aware of exact VB syntax :) Also, you raised a good point about MessageBox, that it will get displayed on server side. I suggest, we can use javascript alerts instead of message box.