[英]ImageButton is not being enabled when using AsyncPostBackTrigger in ajax update panel in asp.net
i am using asp.net with c#. 我正在C#中使用asp.net。 i have two image buttons : open and delete. 我有两个图像按钮:打开和删除。 By default they are disabled ie imgOpen.Enabled = false; imgDelete.Enabled = false;
默认情况下,它们是禁用的,即imgOpen.Enabled = false; imgDelete.Enabled = false;
imgOpen.Enabled = false; imgDelete.Enabled = false;
. 。 I have a GridView which shows search results from table. 我有一个GridView,它显示表中的搜索结果。 GridView contains a radio button which when selected, should enable Open and delete image button. GridView包含一个单选按钮,选中该按钮后应启用“打开并删除图像”按钮。 if I won't use ajax update panel, then every time i select a radio button my page reloads and it's quite disturbing and not friendly. 如果我不使用Ajax更新面板,那么每次我选择一个单选按钮时,我的页面就会重新加载,这很令人不安,也不友好。
<asp:TemplateField>
<ItemTemplate>
<asp:UpdatePanel ID="updateRadioButton" runat="server">
<ContentTemplate>
<asp:RadioButton ID="rdoBtnFileOption" runat="server" OnCheckedChanged="rdoBtnFileOption_CheckedChanged" AutoPostBack="true" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rdoBtnFileOption" EventName="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
protected void rdoBtnFileOption_CheckedChanged(object sender, EventArgs e)
{
imgOpen.Enabled = true;
imgDelete.Enabled = true;
RadioButton curretnRdo = sender as RadioButton;
GridViewRow currentRow = (GridViewRow)curretnRdo.NamingContainer;
int index = currentRow.RowIndex;
try
{
foreach (GridViewRow grv in grdSearchResults.Rows)
{
if (grv.RowType == DataControlRowType.DataRow && grv.RowIndex != index)
{
RadioButton rdo = new RadioButton();
rdo = (RadioButton)(grv.FindControl("rdoBtnFileOption"));
rdo.Checked = false;
}
}
}
catch (Exception ex)
{
form.MessageBox.Show(ex.Message, "Error", form.MessageBoxButtons.OK, form.MessageBoxIcon.Error);
}
}
These two line are not working for me. 这两行对我不起作用。
imgOpen.Enabled = true;
imgDelete.Enabled = true;
Please Suggest any approach. 请提出任何建议。 I hope i am quite clear. 我希望我很清楚。
Try the following 尝试以下
Wrap your imgDelete
with another UpdatePanel
and set UpdateMode=Conditional
and set Trigger 用另一个UpdatePanel
包装imgDelete
并设置UpdateMode=Conditional
并设置Trigger
<asp:UpdatePanel ID="updateRadioButton" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Image ID="imgOpen" runat="server"/>
<asp:Image ID="imgDelete" runat="server"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rdoBtnFileOption"
EventName="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>
or set UpdateMode="Always" and No Triggers
或set UpdateMode="Always" and No Triggers
For using AsyncPostBack, the contents should be in Update panel also. 为了使用AsyncPostBack,其内容也应该在“更新”面板中。
you can use another Asp:UpdatePanel with UpdateMode="Always" having your images in it. 您可以使用另一个具有UpdateMode =“ Always”的 Asp:UpdatePanel,其中包含您的图像。
<asp:UpdatePanel ID="UP1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:ImageButton ID="imgOpen" runat="server" ImageUrl="" Visible="false" AlternateText="this is Open Image" />
<asp:ImageButton ID="imgDelete" runat="server" ImageUrl="" Visible="false" AlternateText="this is Delete Image" />
</ContentTemplate>
</asp:UpdatePanel>
May this Help You. 希望这对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.