[英]TextBox does not get it's value from code behind after postback
please consider this code: 请考虑以下代码:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table border="1" cellpadding="8" cellspacing="0" width="700px" style="background-color: Aqua">
<tr>
<td style="direction: rtl">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td style="direction: ltr">
F1
</td>
</tr>
<tr>
<td style="direction: rtl">
<asp:DropDownList ID="Drp_1" runat="server" ClientIDMode="Static">
<asp:ListItem Value="1">Head of household</asp:ListItem>
<asp:ListItem Value="2">Spouse</asp:ListItem>
<asp:ListItem Value="3">Child</asp:ListItem>
</asp:DropDownList>
</td>
<td>
F2
</td>
</tr>
<tr>
<td style="direction: rtl">
<asp:RadioButtonList ID="Rad_7" runat="server" ClientIDMode="Static">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
F3
</td>
</tr>
<tr>
<td>
<asp:Button ID="BindAgain" runat="server" Height="44px" Text="Submit" ClientIDMode="Static"
Width="207px" OnClick="BindAgain_Click" />
</td>
<td>
<asp:Button ID="btn" runat="server" Height="44px" Text="Submit" ClientIDMode="Static"
Width="207px" OnClick="btn_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:TextBox ID="isPostback" ClientIDMode="Static" runat="server"></asp:TextBox>
<h1 style="color: Green; font-size: large; font-weight: bold; display: none;" id="nima">
Progress ...
</h1>
and this is code bihind: 这是代码的隐藏:
protected void btn_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(4000);
TextBox1.Text = "nima";
}
protected void BindAgain_Click(object sender, EventArgs e)
{
Drp_1.SelectedIndex = 1;
Rad_7.SelectedIndex = 3;
isPostback.Text = "1";
}
when I want to check value of isPostback
after postback using jQuery I get ""
.this is my javascript code: 当我想使用jQuery回
isPostback
后检查isPostback
值时,我得到""
是我的javascript代码:
function pageLoad() {
$('#nima').hide();
$(document).ready(function () {
//alert("NIMA");
$("#Drp_1").on("change", function () {
if ($(this).val() == 2) {
if ($('#Rad_7 input:checked').val() != null && $('#Rad_7 input:checked').val() > 1 && $('#Rad_7 input:checked').val() != 2) {
if ($('#isPostback').val() == "0") {//<<<<<<<<
alert('Wrong option');
}
}
}
else {
$('#Rad_7 input').removeAttr("checked");
}
}).change();
$("#Rad_7 input").on("change", function () {
if ($(this).val() == 2) {
if ($('#Drp_1').val() != null && $('#Drp_1').val() > 1 && $('#Drp_1').val() != 2) {
if ($('#isPostback').val() == "0") {//<<<<<<<<
alert('Wrong option');
}
}
}
if ($("#Drp_1").val() != null && $("#Drp_1").val() == 2) {
if ($('#Rad_7 input:checked').val() != null && $('#Rad_7 input:checked').val() != 'undefiend' && $('#Rad_7 input:checked').val() != 2) {
if ($('#isPostback').val() == "0") {//<<<<<<<<
alert('Wrong option');
}
}
}
}).change();
});
}
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
function InitializeRequest(sender, args) {
$('#nima').css('display', 'block');
}
function EndRequest(sender, args) {
$('#nima').css('display', 'none');
}
where is my mistake? 我的错误在哪里?
thanks 谢谢
Your textbox is outside of the UpdatePanel. 您的文本框在UpdatePanel之外。 It is not receiving the update when the postback is triggered from within the panel.
从面板内部触发回发时,它不接收更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.