Executing Textbox Text
-
i want to execute the text written in text box e.g i have a function public void func(string s) { } what i want to achieve is if i write func("waheed") in the textbox this function should be called on clicking a button i cant use if/case etc my requirement is this the textbox text will be passed to another function where this text will execute as code Thanks
-
i want to execute the text written in text box e.g i have a function public void func(string s) { } what i want to achieve is if i write func("waheed") in the textbox this function should be called on clicking a button i cant use if/case etc my requirement is this the textbox text will be passed to another function where this text will execute as code Thanks
waheed awan wrote:
i want to execute the text written in text box e.g i have a function public void func(string s) { } what i want to achieve is if i write func("waheed") in the textbox this function should be called on clicking a button
If you want this on javascript try the below on the onclick event of the button, (OnClientClick, if it is a Server Side button)
func(document.getElementById('MY_TEXTBOX').value)
If you want the above in ASP.NET, double click button, it will take you to the code behind, where you can try the below code in the Button Click event,
func(MY_TEXTBOX.Text);
Here MY_TEXTBOX is the ID of the textbox you mentioned
[Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot
modified on Tuesday, February 12, 2008 9:52 PM
-
waheed awan wrote:
i want to execute the text written in text box e.g i have a function public void func(string s) { } what i want to achieve is if i write func("waheed") in the textbox this function should be called on clicking a button
If you want this on javascript try the below on the onclick event of the button, (OnClientClick, if it is a Server Side button)
func(document.getElementById('MY_TEXTBOX').value)
If you want the above in ASP.NET, double click button, it will take you to the code behind, where you can try the below code in the Button Click event,
func(MY_TEXTBOX.Text);
Here MY_TEXTBOX is the ID of the textbox you mentioned
[Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot
modified on Tuesday, February 12, 2008 9:52 PM
document.getElementById returns an object. How will this work in your example?
only two letters away from being an asset
-
i want to execute the text written in text box e.g i have a function public void func(string s) { } what i want to achieve is if i write func("waheed") in the textbox this function should be called on clicking a button i cant use if/case etc my requirement is this the textbox text will be passed to another function where this text will execute as code Thanks
First, it isn't a very smart idea to try executing arbitrary code entered from a textbox. If you want to do this on the client-side you need to use the eval function. http://www.w3schools.com/jsref/jsref_eval.asp[^] On the server-side you can try using CodeDOM http://msdn2.microsoft.com/en-us/library/y2k85ax6.aspx[^] However, it is VERY, VERY dangerous to try compiling code input from a textbox. Don't even think about it, try something else.
only two letters away from being an asset
-
document.getElementById returns an object. How will this work in your example?
only two letters away from being an asset
It should be
func(document.getElementById('MY_TEXTBOX').value);
Thanks Marks for pointing out.
[Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot
-
First, it isn't a very smart idea to try executing arbitrary code entered from a textbox. If you want to do this on the client-side you need to use the eval function. http://www.w3schools.com/jsref/jsref_eval.asp[^] On the server-side you can try using CodeDOM http://msdn2.microsoft.com/en-us/library/y2k85ax6.aspx[^] However, it is VERY, VERY dangerous to try compiling code input from a textbox. Don't even think about it, try something else.
only two letters away from being an asset
THANKS the arical you gave me reference is very helpful and it solved another problem that i was facing but here my problem is as i write func("vaue"); in the cs file the function is called what i want to achieve is when i write func("vaue"); in the textbox then on clicking the button the textbox should be executed
-
First, it isn't a very smart idea to try executing arbitrary code entered from a textbox. If you want to do this on the client-side you need to use the eval function. http://www.w3schools.com/jsref/jsref_eval.asp[^] On the server-side you can try using CodeDOM http://msdn2.microsoft.com/en-us/library/y2k85ax6.aspx[^] However, it is VERY, VERY dangerous to try compiling code input from a textbox. Don't even think about it, try something else.
only two letters away from being an asset
THANKS the arical you gave me reference is very helpful and it solved another problem of adding a class that i was facing but here my problem is as i write func("vaue"); in the cs file the function is called what i want to achieve is when i write func("vaue"); in the textbox then on clicking the button the textbox text should be executed
-
THANKS the arical you gave me reference is very helpful and it solved another problem that i was facing but here my problem is as i write func("vaue"); in the cs file the function is called what i want to achieve is when i write func("vaue"); in the textbox then on clicking the button the textbox should be executed
waheed awan wrote:
then on clicking the button the textbox should be executed
I don't understand what you are asking for here.:confused: Do you want something like; func("Console.WriteLine("Hello, World");" ) which causes "Hello, World" to be written to a console window?:confused:
only two letters away from being an asset
-
waheed awan wrote:
then on clicking the button the textbox should be executed
I don't understand what you are asking for here.:confused: Do you want something like; func("Console.WriteLine("Hello, World");" ) which causes "Hello, World" to be written to a console window?:confused:
only two letters away from being an asset
i want to say the textbox will be used to write code statements and clicking the button will execute the statement written in the textbox Example; if in the textbox i write MessageBox.Show("Hello"); then clicking the button executes the statement in the textbox in this case display a messagebox
-
i want to say the textbox will be used to write code statements and clicking the button will execute the statement written in the textbox Example; if in the textbox i write MessageBox.Show("Hello"); then clicking the button executes the statement in the textbox in this case display a messagebox
Then read my previous response about CodeDOM, and the warning that this is VERY dangerous thing, don't do it, think of another way.
only two letters away from being an asset