Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a value from server side page to client side function in asp.net

Tags:

c#

asp.net

In my application I need to pass a string value from the server side(.aspx.cs) to a function in the client side (.aspx) page.

Can anyone help me by providing ideas and sample code if possible?

like image 795
Pranesh Nair Avatar asked Jul 30 '10 13:07

Pranesh Nair


1 Answers

If you mean that you need to pass the value to a javascript function, what you can do is something like this...

In the .aspx file:

<script language="javascript" type="text/javascript">
  var stringValue = '<%=GetStringValue();%>';

  // For example:

  alert(stringValue);
</sctipt>

In the .aspx.cs file:

private string GetStringValue()
{
  return "A string value";
}

This would then show a javascript messagebox saying "A string value" when the page loads

like image 84
Rob Avatar answered Oct 02 '22 00:10

Rob