我在UpdatePanel中有一个网格和几个文本框。在选择特定行时,使用JS填充文本框。引入UpdatePanel是因为使用代码中的方法填充了一个文本框。 网格行中还有一个链接,用于打开弹出窗口(也可以从后面的代码填充)。
使用UpdatePanel后链接无法正常工作(假设没有完整的回发)。
我尝试使用UpdateMode ="条件"属性和注册PostBAck控件的链接控件。 但它仍然无效:
代码
<asp:UpdatePanel ID="Update" runat="server" Up>
<ContentTemplate>
<table width="100%">
<tr>
<td>
<asp:GridView ID="gvSession" BorderColor="#ffcc00" RowStyle-BorderColor="#ffcc00"
AutoGenerateColumns="False" Font-Names="Verdana" DataKeyNames="SessionId" runat="server"
RowStyle-BorderStyle="Solid" RowStyle-BorderWidth="1px" GridLines="Both" Width="100%"
OnRowCreated="gvSession_RowCreated" OnDataBound="gvSession_DataBound">
<RowStyle CssClass="dbGrid_Table_row" />
<HeaderStyle CssClass="dbGrid_Table_Header" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="rbSelect" onclick="javascript:CheckOtherIsCheckedByGVIDMore(this);"
runat="server" OnCheckedChanged="rbSelect_CheckedChanged" AutoPostBack="True" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Session Name">
<ItemTemplate>
<asp:Label ID="lblSessionName" Text='<%# Eval("SessionName") %>' runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="16%"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Preview">
<ItemTemplate>
<asp:LinkButton ID="lbPreview" Text="Preview" CommandName="Preview" AutoPostBack="true"
CommandArgument='<%# Eval("SessionId") + ";" + Eval("TrainingTypeName") %>'
runat="server" OnClick="lbPreview_Click"></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="10%"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
<table id="Table2" runat="server" width="100%">
<tr>
<td colspan="2" align="center" style="text-align: center">
<asp:TextBox ID="txtSessionDtl" runat="server" Font-Size="Small" Style="text-align: center"
ForeColor="Black" Wrap="true" Height="20px" Width="95%" BorderStyle="None"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 12%">
<asp:Label ID="Label9" CssClass="label" runat="server">Upload File : </asp:Label>
</td>
<td>
<asp:TextBox ID="txtFilePath" Enabled="false" BorderStyle="Solid" BorderColor="Black"
runat="server" Width="741px"></asp:TextBox>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
代码背后:
链接点击:
protected void lbPreview_Click(object sender, EventArgs e)
{
try
{
LinkButton link = (LinkButton)sender;
GridViewRow gv = (GridViewRow)(link.Parent.Parent);
LinkButton linkPreview = (LinkButton)gv.FindControl("lbPreview");
string[] arg = new string[2];
arg = linkPreview.CommandArgument.ToString().Split(';');
string strSessionId = arg[0];
string strTrgType = arg[1];
string mailContent = GenerateNominationMailer(strSessionId, strTrgType);
hidMailContent.Value = mailContent;
string mailContent1 = mailContent.Replace(System.Environment.NewLine, "");
string myScript = "<SCRIPT LANGUAGE='javascript'>";
myScript = myScript + " my_window = window.open('', '', 'status=1,width=1000,height=800,scrollbars=yes');";
myScript = myScript + " my_window.document.write(\"" + mailContent1.Replace("\"", "'") + "\");";
myScript = myScript + " my_window.document.close();";
myScript = myScript + " </script>";
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Nomination Mailer", myScript,false);
}
catch (Exception ex)
{
AlnErrorHandler.HandleError(ex);
}
}
注册控制:
protected void gvSession_DataBound(object sender, EventArgs e)
{
foreach (GridViewRow grdrow in gvSession.Rows)
{
LinkButton Preview = (LinkButton)grdrow.FindControl("lbPreview");
ScriptManager current = ScriptManager.GetCurrent(Page);
if (current != null)
current.RegisterPostBackControl(Preview);
}
}
enter code here
答案 0 :(得分:0)
为您的活动设置触发器。把它放在ContentTemplate的末尾
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbPreview" EventName="Click" />
</Triggers>
答案 1 :(得分:0)
用此
替换旧事件protected void gvSession_DataBound(object sender, GridViewRowEventArgs e)
{
LinkButton Preview = e.Row.FindControl("lbPreview") as LinkButton;
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(Preview);
}
并在GridView中将gvSession_DataBound事件指定为DataBound事件