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. Get text in a textbox

Get text in a textbox

Scheduled Pinned Locked Moved ASP.NET
helpquestion
5 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.
  • O Offline
    O Offline
    Otekpo Emmanuel
    wrote on last edited by
    #1

    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 Sub

    But if the Add idea button is heat, the msgbox returns an empty string. Help please.

    A Richard DeemingR 2 Replies Last reply
    0
    • O Otekpo Emmanuel

      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 Sub

      But if the Add idea button is heat, the msgbox returns an empty string. Help please.

      A Offline
      A Offline
      Abhipal Singh
      wrote on last edited by
      #2

      Debug your code and check what is the value you are getting in txt variable. It looks like txtidea control is not found by FindControl() 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.

      Richard DeemingR 1 Reply Last reply
      0
      • A Abhipal Singh

        Debug your code and check what is the value you are getting in txt variable. It looks like txtidea control is not found by FindControl() 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.

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        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

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        A 1 Reply Last reply
        0
        • O Otekpo Emmanuel

          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 Sub

          But if the Add idea button is heat, the msgbox returns an empty string. Help please.

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          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

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            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

            A Offline
            A Offline
            Abhipal Singh
            wrote on last edited by
            #5

            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.

            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