请考虑以下代码:
<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>
这是代码背后:
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";
}
当我想在使用jQuery回发后检查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');
}
我的错误在哪里?
感谢
答案 0 :(得分:1)
您的文本框位于UpdatePanel之外。当从面板内触发回发时,它没有收到更新。