gpt4 book ai didi

c# - 当多个用户在 Gridview 中选择同一行时,Java 脚本弹出框

转载 作者:行者123 更新时间:2023-12-03 12:29:12 24 4
gpt4 key购买 nike

我有一个包含许多行的 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());
}
}

GridView

<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>
<asp:AsyncPostBackTrigger ControlID="TimerGVMain" />
</Triggers>-->

编辑2

或者,您可以将 Timer 保留在原处,并通过为 Timer 添加 EventName 来更改 Triggers :

<Triggers>
<asp:AsyncPostBackTrigger ControlID="TimerGVMain" EventName="Tick" />
</Triggers>

关于c# - 当多个用户在 Gridview 中选择同一行时,Java 脚本弹出框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24018781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com