Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User control problem

Status
Not open for further replies.

liorlankril

Programmer
Nov 5, 2005
46
IL

I have a User Control that contain this c# code:

public partial class MyUC: Moia.Components.BaseUserControl
{
protected string str = string.Empty;

protected void Page_Load(object sender, EventArgs e)
{

this.str= "aaa";


string strScriptKey = "Replace";
string strScriptCode = "<script type='text/jscript' language='javascript'> " +
"function ShowAlert(strToShow) " +
"{ " +

"alert(strToShow); " +
"} "+

"ShowAlert(" + this.str +"); "+

"</script>";

if (!Page.IsClientScriptBlockRegistered(strScriptKey))
Page.RegisterClientScriptBlock(strScriptKey,
strScriptCode);

}

As you can see, all I did is define string str="aaa" and to Register javascript code that contain function (ShowAlert) and calling to this function with "str" as parameter.

I get an error on page : 'aaa" is undefiend

What is the problem?????
 
in JScript you get aaa as a variable, not text, so change the line into the following:

Code:
"ShowAlert('" + this.str +"'); "

btw, use [ code ], [ /code ] tags when posting code.

------------------
When you do it, do it right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top