ASP.NET VB Execute a String to Change Label Text
-
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 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: :~ :~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 -
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 -
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
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
-
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
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?
-
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?
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
-
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
-
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