Весь мой javascript на код позади. Я хочу получить значение javascript var EmailId для моих данных ajax позади кода. Но поскольку я должен написать это в двойных кавычках, это вызывает массу проблем. Вот мой код,Получить значение javascript var из кода позади
protected void Page_Load(object sender, EventArgs e)
{
//HttpResponse response = HttpContext.Current.Response;
//response.AddHeader("X-Frame-Options", "GOFORIT");
//Response.AddHeader("X-Frame-Options", "GOFORIT");
Session["txtEmail"] = txtEmail;
if (!IsPostBack)
{
GetItemsList();
Session["ProfileImage"] = imgProfilePicture;
if (Convert.ToBoolean(Session["GotToken"]) == true)
{
GetProfilePic();
}
if (HttpContext.Current.Request.QueryString["code"] != null)
{
Session["code"] = HttpContext.Current.Request.QueryString["code"];
string success = TestFB.AllowAppAuthentication(Convert.ToString(Session["ItemID"]));
StringBuilder sb = new StringBuilder();
var javacriptVariable = "<%= $('#txtEmail').val() %>";
sb.Append("jQuery(function() { ");
sb.Append(@"jQuery('#dialog-form').dialog({
autoOpen: true,
height: 500,
width: 500,
modal: true,
buttons: {
'Participate': function() {
var bValid = true;
var EmailId = $('#txtEmail').val();
var chkTermsAndConditions = document.getElementById('chkTermsAndConditions').checked;
if (bValid && chkTermsAndConditions == true) {
console.log(EmailId);
$('p.validateTips').text('');
$.ajax({
type: 'POST',
url: 'FitbookContest.aspx/InsertUsersItem',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: " + "\"{'email':'" + javacriptVariable + "', 'ItemId':'" + Convert.ToString(Session["ItemID"]) + "'}\"," +
" success: function (data) { " +
"console.log(EmailId); " +
"$('#lblErrorMessage').text(''); " +
"document.getElementById('chkTermsAndConditions').checked = false; " +
"if (data.d == false) { " +
"alert('Sorry!You can participate only once!'); " +
"$(this).dialog('close'); " +
"} else { " +
"alert('Email will be sent to your Account soon!'); " +
"$(this).dialog('close'); " +
"} " +
"}, " +
"context: $(this), " +
"}); " +
"} " +
"}, " +
"Cancel: function() { " +
"document.getElementById('chkTermsAndConditions').checked = false; " +
"$(this).dialog('close'); " +
"} " +
"}, " +
"close: function() { " +
"$(this).dialog('close'); " +
"} " +
"});");
sb.Append(" }); ");
//ClientScript.RegisterStartupScript(this.GetType(), "popup", sb.ToString(), true);
ScriptManager.RegisterStartupScript(this, GetType(), "modalscript", sb.ToString(), true);
}
}
}
Я хочу открыть всплывающее окно на странице загрузки! а также хотите получить электронное письмо, которое будет написано в текстовом поле pop up. Я могу получить его только с помощью javascript. Но из-за двойных кавычек на код позади я не могу получить его на «данные» как [ data: " + "\"{'email':'" + javacriptVariable + "', 'ItemId':'" + Convert.ToString(Session["ItemID"]) + "'}\"," + ].
Пожалуйста, помогите мне. Предложения приветствуются!