0

Possible Duplicate:
convert javascript variable to C# variable

I have a c# code in which JavaScript code is embedded. I need to pass the variable label to C# function.. Is this possible? if then how can I achieve it?

StringBuilder ts = new StringBuilder("<script language='javascript' type='text/javascript'>");
ts.Append(var label="testLabel";);
ts.Append("</script>");  
HtmlGenericControl div = new HtmlGenericControl("div");
div.Attributes.Add("id",DivId);
div.InnerHtml = ts.ToString();
Container.Controls.Add(div);
4

3 Answers 3

0

No C# is server side. JS is client side. Unless you are talking about a WebControl or something. Otherwise the closest is AJAX

Sign up to request clarification or add additional context in comments.

1 Comment

Can you please tell how can i do it using ajax? any example links?
0

Check code below ...

`StringBuilder ts = new StringBuilder("<script language='javascript' type='text/javascript'>");
 ts.Append("var label='testLabel';");
 ts.Append("</script>");  
 HtmlGenericControl div = new HtmlGenericControl("div");
 div.Attributes.Add("id",DivId);
 div.InnerHtml = ts.ToString();
 Container.Controls.Add(div);

`

Comments

0

Response.Write(ts.ToString()); in your aspx if you have one

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.