我有一个 updatePanel ,其文本框作为内容,下拉列表作为触发。 每当我更改下拉列表的 selectedIndex 时,它都会查询数据库,它会为文本框提供值
现在我输入了一些新的值,然后点击更新 按钮,这样它就会保存在数据库中。
这里的问题,它不断给我带来旧的值(下拉列表带来的价值)。
我怎么能解决这个问题?
修改
<asp:UpdatePanel ID="uplKmAllowed" runat="server">
<ContentTemplate>
<dx:ASPxTextBox ID="txtKmAllowed" runat="server" Width="215px" OnTextChanged="txtKmAllowed_TextChanged">
</dx:ASPxTextBox>
</ContentTemplate>
</asp:UpdatePanel>
代码背后:这是以编程方式添加触发器,因为cboAsset位于用户控件中
asset = fltrAsset.FindControl("cboAsset") as ASPxComboBox;
asset.AutoPostBack = true;
asset.SelectedIndexChanged += new EventHandler(Asset_SelectIndexChanged);
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = asset.UniqueID;
trigger.EventName = "SelectedIndexChanged";
uplKmAllowed.Triggers.Add(trigger);
功能
protected void Asset_SelectIndexChanged(object sender, EventArgs e)
{
string tudID = asset.SelectedItem.Value.ToString();
RentalTracking rtk = new RentalTracking();
string assetID = rtk.getAssetIDDepartmentIDbyTudID(tudID)[1];
RentalAssetInfo rai = new RentalAssetInfo();
rai.GetRentalAssetInfo(Int32.Parse(assetID));
if (rai.KMAllowed == 0 || rai.KMAllowed == -1 || rai.KMAllowed == null)
{
kmallowedSaved = false;
txtKmAllowed.Text = "";
}
else
{
txtKmAllowed.Text = rai.KMAllowed.ToString();
}
}
答案 0 :(得分:-1)
use asp:AsyncPostBackTrigger in update panel
<asp:UpdatePanel ID="uplKmAllowed" runat="server">
<ContentTemplate>
<dx:ASPxTextBox ID="txtKmAllowed" runat="server" Width="215px" OnTextChanged="txtKmAllowed_TextChanged">
</dx:ASPxTextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="LnkEditBuyingLead" EventName="EventName"/>
</Triggers>
</asp:UpdatePanel>