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);
Community
  • 1
  • 1
sharmila
  • 1,493
  • 5
  • 23
  • 42

3 Answers3

0

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

Cole Tobin
  • 9,206
  • 15
  • 49
  • 74
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);

`

Lajja Thaker
  • 2,031
  • 8
  • 33
  • 53
0

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

God Dices
  • 51
  • 3