Q:

Use js variables in C# Webform(ASP.net)

I have created some variables in my JS file and linked it to my webform in Xhtml code, my js code is as follows:
var access_key = 'my key';
var email_address;
var valid_format,smtp_check,disposable,mxfound,Urole;
// verify email address via AJAX call
function verify()
{
$.ajax({
url: 'domain/api/check?access_key=' + access_key + '&email=' + 
email_address,
dataType: 'jsonp',
success: function validate(json) {
valid_format = json.valid_format ;
smtp_check = json.smtp_check ;
disposable = json.disposable;
mxfound = json.mxfound ;
Urole = json.role ;
}
});
}

I need to use variables (valid_format,smtp_check,disposable,mxfound,Urole) from the js part in the Signup.aspx.cp file. 
Note: I have linked myJs.js to Signup.aspx file.(myJs is not original name just for example purposes)

A:

These easiest thing to do is probably add some HiddenField server controls and put your values in them clientside, then you can reference the HiddenField controls in your C# code upon the next postback.
For example to do the valid_format value:
<asp:HiddenField runat="server" ID="hdnValidFormat" ClientIDMode="Static" />

Then use jQuery to set the value in your success callback:
$('#hdnValidFormat').val(json.valid_format); 

Then you can just reference hdnValidFormat.Value in your C# code like normal.
Then just do the same for the other variables.
Notes:

Make sure you have ViewState enabled for the HiddenField controls or the values won't persist across postbacks.
If you can't/don't want to use ClientIDMode="Static" on your HiddenField controls, you can use the default dynamically generated ID, you'll just have to reference them using server code like:
$('#<%=hdnValidFormat.ClientID%>').val(...);
Be careful that you don't do this with values that could be manipulated and compromise the security of your app.  All someone would have to do is edit the markup and they could put whatever values they wanted in there.

