I have JQuery Popup whchi has a textbox. JQuery Popup trigger on OnClick event of a Checkbox.
HTML
JavaScript
x
7
1
<div id="popupdiv" title="Basic modal dialog" style="display: none"> Enter Password
2
<asp:TextBox ClientID="pass" ClientIDMode="static" runat="server" class="textcss" ></asp:TextBox></div>
3
<div id="DiscountEnd" style="display: none"></div>
4
5
<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);"/>
6
<asp:Button ID="btnDiscountAtEnd" runat="server" style="display:none;" Text="Button" OnClick="btnDiscountAtEnd_Click" />
7
My effort is to receive textbox value in server side C# Code and display it using an other jquery popup
Server Side Code C#
JavaScript
1
3
1
string discountEnd = Request.Form["discount_end"];
2
ScriptManager.RegisterStartupScript(this, this.GetType(), "p", "<script>MessageBox('" + discountEnd + "');</script>", false);
3
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
JavaScript
1
39
39
1
function DiscountAtLast(chk) {
2
$(function () {
3
var discount_end = document.createElement("INPUT");
4
discount_end.type = "hidden";
5
discount_end.name = "discount_end";
6
7
if (chk.checked) {
8
9
$("#popupdiv").dialog({
10
title: "Login Info",
11
resizable: false,
12
height: "auto",
13
width: 400,
14
buttons: {
15
Cancel: function () {
16
$(this).dialog("close");
17
discount_end.value = $("[id*=pass]").val();
18
document.forms[0].appendChild(discount_end);
19
20
return false;
21
22
},
23
Ok: function () {
24
25
$(this).dialog("close");
26
discount_end.value = $("[id*='pass']").val()
27
document.forms[0].appendChild(discount_end);
28
29
__doPostBack('<%=btnDiscountAtEnd.UniqueID%>', "");
30
31
return true;
32
33
}
34
}
35
});
36
}
37
});
38
}
39
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