I am going to pass an variable from asp.net server to the javascript but I got an exception.
The name ‘serializer’ does not exist in the current context
In my Admin.aspx.cs
protected static string urlEdit;
protected void Page_Load(object sender, EventArgs e)
{
// blah blah...
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
}
Then in the markup code:
<script type="text/javascript">
function Edit_Click() {
var options = SP.UI.$create_DialogOptions();
options.url = <%= serializer.Serialize(urlEdit) %>;
};
serializeronly exists inPage_Load. Instead of accessing serializer from your markup, why not create public method or property that returns the serialized value instead?Then call this method in your markup:
Update
Actually … you don’t need to serialize a string to use it javascript. So your code could be simplified to the following:
And the simplified markup: