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. General Programming
  3. Visual Basic
  4. ASP.NET VB Execute a String to Change Label Text

ASP.NET VB Execute a String to Change Label Text

Scheduled Pinned Locked Moved Visual Basic
helpcsharpasp-netlearning
8 Posts 2 Posters 1 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.
  • E Offline
    E Offline
    etihwl
    wrote on last edited by
    #1

    I am new to ASP.NET and looking for help. I am attempting to change the text on objects dropdowns, textbox, and so on. I reviewed the information on executing string but I am having problems, below is the code and the error. Could someone tell me what I am doing wrong. Thank you. Dim exeInstrt as string = "BUTN2.text = 'WORKS2'" exeInstrt = Replace(exeInstrt,"'","''") Execute(exeInstrt) Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30469: Reference to a non-shared member requires an object reference. Source Error: Line 19: Dim exeInstrt as string = "BUTN2.text = 'WORKS2'" Line 20: exeInstrt = Replace(exeInstrt,"'","''") Line 21: Execute(exeInstrt) Line 22: ' Response.Write(exeInstrt & "
    ") Line 23: :~ :~

    I 1 Reply Last reply
    0
    • E etihwl

      I am new to ASP.NET and looking for help. I am attempting to change the text on objects dropdowns, textbox, and so on. I reviewed the information on executing string but I am having problems, below is the code and the error. Could someone tell me what I am doing wrong. Thank you. Dim exeInstrt as string = "BUTN2.text = 'WORKS2'" exeInstrt = Replace(exeInstrt,"'","''") Execute(exeInstrt) Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30469: Reference to a non-shared member requires an object reference. Source Error: Line 19: Dim exeInstrt as string = "BUTN2.text = 'WORKS2'" Line 20: exeInstrt = Replace(exeInstrt,"'","''") Line 21: Execute(exeInstrt) Line 22: ' Response.Write(exeInstrt & "
      ") Line 23: :~ :~

      I Offline
      I Offline
      Ian Darling
      wrote on last edited by
      #2

      What's wrong with just doing a: BUTN2.Text = """WORKS2""" In your aspx.vb code-behind? (Note that the extra quotes are there to put a " in a string literal, you type "", so the actual string has a value of "WORKS2") Or is this a Javascript/VBScript client side thing you are trying to do? -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

      E 1 Reply Last reply
      0
      • I Ian Darling

        What's wrong with just doing a: BUTN2.Text = """WORKS2""" In your aspx.vb code-behind? (Note that the extra quotes are there to put a " in a string literal, you type "", so the actual string has a value of "WORKS2") Or is this a Javascript/VBScript client side thing you are trying to do? -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

        E Offline
        E Offline
        etihwl
        wrote on last edited by
        #3

        I need to do this dynamically it is for Languages in many ASP>NET pages and it is driven from a Data Base table. Sorry for the lack of information

        I 1 Reply Last reply
        0
        • E etihwl

          I need to do this dynamically it is for Languages in many ASP>NET pages and it is driven from a Data Base table. Sorry for the lack of information

          I Offline
          I Offline
          Ian Darling
          wrote on last edited by
          #4

          So you want to internationalize an ASP.NET application based on a database back end? Why not just DataBind the Text property to a function that retrieves the text from your database? In your Page_Load, just call MyControl.DataBind() eg:

          <asp:Label id='MyControl' Text='<%# GetText('MyControl') %>'></asp:label>
          

          and

          Protected Function GetText(ControlName as String) as String
           ' I know what language the user wants, as I've 
           ' probably stored it in the Session or something.  Do whatever I need to
           ' do to get the text from the database or something.  Then Return it.
          End Function
          

          -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

          E 1 Reply Last reply
          0
          • I Ian Darling

            So you want to internationalize an ASP.NET application based on a database back end? Why not just DataBind the Text property to a function that retrieves the text from your database? In your Page_Load, just call MyControl.DataBind() eg:

            <asp:Label id='MyControl' Text='<%# GetText('MyControl') %>'></asp:label>
            

            and

            Protected Function GetText(ControlName as String) as String
             ' I know what language the user wants, as I've 
             ' probably stored it in the Session or something.  Do whatever I need to
             ' do to get the text from the database or something.  Then Return it.
            End Function
            

            -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

            E Offline
            E Offline
            etihwl
            wrote on last edited by
            #5

            This is good and we can use this elsewhere but all the Objects and all the Dim's that are messages and or error code messages are in this table for all languages of out applications. The code below is the code we will be using. ***************************** sub bindLanguage() Dim Strconn99 as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AAA MS Access\POS.mdb;" Dim Conn99 as new OLEDBConnection(strconn99) Dim Rdr99 as OLEDBDatareader Dim Cmd99 as OLEDBCommand Dim strSQL99 as string STRSQL99 = "SELECT LANG FROM POS_USRPROFL " & _ " WHERE USERID = '" & UserID & "' " Cmd99=New OLEDBCommand(strSQL99,Conn99) Conn99.Open() Rdr99 = Cmd99.executereader() 'A while Rdr99.read <> false LanguageID = rdr99(0) end while rdr99.close conn99.close if LanguageID = "" then else STRSQL99 = "SELECT OBJNM, TXTVAL " & _ " FROM POS_LANGUAGE " & _ " WHERE PAGENM = 'POS_View_Log_Language' " & _ " AND LANGCD = '" & LanguageID & "' " Cmd99=New OLEDBCommand(strSQL99,Conn99) Conn99.Open() Rdr99 = Cmd99.executereader() 'B while Rdr99.read <> false Dim exeInstrt as string = Rdr99(0) & " = '" & Rdr99(1) & "'" exeInstrt = Replace(exeInstrt,"'","''") ' Execute(exeInstrt) end while rdr99.close conn99.close() end if end sub *********************************** What we are looking for is a way to execute a string dynamically. This is the code that is not working --> Execute(exeInstrt) <--. We can see other uses for executing a string dynamically. Do you know of anyway this can be done?

            I 1 Reply Last reply
            0
            • E etihwl

              This is good and we can use this elsewhere but all the Objects and all the Dim's that are messages and or error code messages are in this table for all languages of out applications. The code below is the code we will be using. ***************************** sub bindLanguage() Dim Strconn99 as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AAA MS Access\POS.mdb;" Dim Conn99 as new OLEDBConnection(strconn99) Dim Rdr99 as OLEDBDatareader Dim Cmd99 as OLEDBCommand Dim strSQL99 as string STRSQL99 = "SELECT LANG FROM POS_USRPROFL " & _ " WHERE USERID = '" & UserID & "' " Cmd99=New OLEDBCommand(strSQL99,Conn99) Conn99.Open() Rdr99 = Cmd99.executereader() 'A while Rdr99.read <> false LanguageID = rdr99(0) end while rdr99.close conn99.close if LanguageID = "" then else STRSQL99 = "SELECT OBJNM, TXTVAL " & _ " FROM POS_LANGUAGE " & _ " WHERE PAGENM = 'POS_View_Log_Language' " & _ " AND LANGCD = '" & LanguageID & "' " Cmd99=New OLEDBCommand(strSQL99,Conn99) Conn99.Open() Rdr99 = Cmd99.executereader() 'B while Rdr99.read <> false Dim exeInstrt as string = Rdr99(0) & " = '" & Rdr99(1) & "'" exeInstrt = Replace(exeInstrt,"'","''") ' Execute(exeInstrt) end while rdr99.close conn99.close() end if end sub *********************************** What we are looking for is a way to execute a string dynamically. This is the code that is not working --> Execute(exeInstrt) <--. We can see other uses for executing a string dynamically. Do you know of anyway this can be done?

              I Offline
              I Offline
              Ian Darling
              wrote on last edited by
              #6

              Junk the idea of executing code like that - it isn't practical. If you want to get all the language strings in one go, store the resultset in a DataTable instead of looping through a DataReader, and then just pull them out of that using the DataBinding mechanism I described earlier for controls, and a straight function call for anything else. You'll need an OLEDBDataAdapter to Fill the DataTable. A colleague has suggested that you can use the Eval statement if you use JScript.NET as your code behind language, but neither of us recommend this approach, as it's intended for ASP application migration. -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

              E 1 Reply Last reply
              0
              • I Ian Darling

                Junk the idea of executing code like that - it isn't practical. If you want to get all the language strings in one go, store the resultset in a DataTable instead of looping through a DataReader, and then just pull them out of that using the DataBinding mechanism I described earlier for controls, and a straight function call for anything else. You'll need an OLEDBDataAdapter to Fill the DataTable. A colleague has suggested that you can use the Eval statement if you use JScript.NET as your code behind language, but neither of us recommend this approach, as it's intended for ASP application migration. -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

                E Offline
                E Offline
                etihwl
                wrote on last edited by
                #7

                OK Thank you for your time and I will look into this Thanks again.

                I 1 Reply Last reply
                0
                • E etihwl

                  OK Thank you for your time and I will look into this Thanks again.

                  I Offline
                  I Offline
                  Ian Darling
                  wrote on last edited by
                  #8

                  etihwl wrote: OK Thank you for your time and I will look into this Thanks again. No problem :-) -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

                  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