[英]Java Script Pop Up box when Multiple User selects same Row in Gridview
我有很多行的gridview与第一行的SELECT链接。 一次许多用户使用gridview。 当两个用户同时单击同一行时,将向一个职员显示一个弹出框,表明一个项目是由另一个用户选择的。
我下面有这个JavaScript代码,但没有显示弹出框。
protected void gvTypes_SelectedIndexChanged(object sender, EventArgs e)
{
if (condition)
{
StringBuilder sb = new StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append("The following item has been chosen by another user. Please choose another one. \\n\\n" + row.Cells[3].Text + "\\n");
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
}
网格视图
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvTypes" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
Width="688px" AllowPaging="True" AutoGenerateColumns="false" OnSelectedIndexChanged="gvTypes_SelectedIndexChanged"
Font-Size="14px" PageSize="11" DataKeyNames="TicketId, TicketNumber, LinkedTicketId"
OnRowCommand="gvMain_RowCommand" OnPageIndexChanging="gvMain_PageIndexChanging">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowSelectButton="True"/>
<asp:BoundField DataField="TicketId" HeaderText="Ticket Id" SortExpression="TicketId"
Visible="false">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="TicketNumber" HeaderText="Ticket #Id" SortExpression="TicketNumber"
Visible="false">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#999999" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TimerGVMain" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" Interval="5200" runat="server" OnTick="TimerGVMain_Tick">
</asp:Timer>
我不确定您的其余代码,但是根据问题所在,如果您将脚本注册到ScriptManager
,它应该可以工作:
protected void gvTypes_SelectedIndexChanged(object sender, EventArgs e)
{
if (condition)
{
StringBuilder sb = new StringBuilder();
// Using function pageLoad() to execute the script
// whenever the page is fully or partially loaded (AJAX).
sb.Append("function pageLoad() {");
sb.Append("alert('");
sb.Append("The following item has been chosen by another user. Please choose another one. \\n\\n" + row.Cells[3].Text + "\\n");
sb.Append("')}");
// UpdatePanel1 needs to be replaced with your UpdatePanel ID.
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, typeof(UpdatePanel), "alert", sb.ToString(), true);
}
}
MSDN ScriptManager.RegisterClientScriptBlock
编辑
您可以通过将Timer
移到UpdatePanel
来稍微更改标记:
<ContentTemplate>
<asp:Timer ID="Timer1" Interval="5200" runat="server" OnTick="TimerGVMain_Tick"></asp:Timer>
</ContentTemplate>
并删除Triggers
:
<!--<Triggers>
<asp:AsyncPostBackTrigger ControlID="TimerGVMain" />
</Triggers>-->
编辑2
或者,您可以将Timer
保留在原处,并通过为Timer
添加EventName
来更改Triggers
:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TimerGVMain" EventName="Tick" />
</Triggers>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.