I have JQuery Popup whchi has a textbox. JQuery Popup trigger on OnClick event of a Checkbox.
HTML
<div id="popupdiv" title="Basic modal dialog" style="display: none"> Enter Password
<asp:TextBox ClientID="pass" ClientIDMode="static" runat="server" class="textcss" ></asp:TextBox></div>
<div id="DiscountEnd" style="display: none"></div>
<asp:CheckBox ID="DiscountAtEnd" Text="Offer Discount" style="margin-left:10px;float:left;margin-top:3px;padding-right:27px; " ForeColor="#008269" Font-Bold="false" runat="server" AutoPostBack="True" OnClick="return DiscountAtLast(this);"/>
<asp:Button ID="btnDiscountAtEnd" runat="server" style="display:none;" Text="Button" OnClick="btnDiscountAtEnd_Click" />
My effort is to receive textbox value in server side C# Code and display it using an other jquery popup
Server Side Code C#
string discountEnd = Request.Form["discount_end"];
ScriptManager.RegisterStartupScript(this, this.GetType(), "p", "<script>MessageBox('" + discountEnd + "');</script>", false);
Problem
My server side code can receive JQuery popup textbox value but every time i get the same value which was entered at first time after page load. I thhink there is some variable initialization but could not figure out
JQuery
function DiscountAtLast(chk) {
$(function () {
var discount_end = document.createElement("INPUT");
discount_end.type = "hidden";
discount_end.name = "discount_end";
if (chk.checked) {
$("#popupdiv").dialog({
title: "Login Info",
resizable: false,
height: "auto",
width: 400,
buttons: {
Cancel: function () {
$(this).dialog("close");
discount_end.value = $("[id*=pass]").val();
document.forms[0].appendChild(discount_end);
return false;
},
Ok: function () {
$(this).dialog("close");
discount_end.value = $("[id*='pass']").val()
document.forms[0].appendChild(discount_end);
__doPostBack('<%=btnDiscountAtEnd.UniqueID%>', "");
return true;
}
}
});
}
});
}
Requirement
Value receive at server side C# should be same as per textbox input value each time
Advertisement
Answer
I did not initialize my dialog i.e popupdiv
put $("[id*=popupdiv]").empty();just before return statement of JQuery Script
