简体   繁体   English

Gridview弹出窗口未从与Linkbutton单击相对应的RowCommand事件中打开

[英]Gridview popup window not opening from RowCommand event corresponding to Linkbutton click

I have Linkbutton in the Gridview TemplateField. 我在Gridview TemplateField中有Linkbutton。 I want to Redirect to another Page in a popup Custom size window from RowCommand Event. 我想从RowCommand事件重定向到弹出的“自定义大小”窗口中的另一个页面。

Note: Here I don't want to call OnClientScript property of LinkButton to openJavascript Popup Custom Size Window. 注意:在这里,我不想调用LinkBut​​ton的OnClientScript属性来打开Javascript弹出窗口自定义大小窗口。 I want to save Gridrow into Session object and open window from Serverside code only. 我想将Gridrow保存到Session对象中,并仅从Serverside代码打开窗口。

Here is the Code: 这是代码:

<ItemTemplate>
    <itemstyle width="5%" />
    <asp:LinkButton CssClass="l_link" ID="lnkView" runat="server"  
      DataTextField="overWriteType" 
      CommandName="overWriteType"
      CommandArgument='<%# Eval("overWriteType") %>'
      Text='<%# Eval("overWriteType") %>'></asp:LinkButton>
</ItemTemplate>
protected void gvKeys_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "overWriteType")
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("&lt;script language='javascript'>");
        sb.Append("window.open('OverwriteConfiguration.aspx', 'PopUp',");
        sb.Append("'top=0, left=0, width=500, height=500, menubar=no,toolbar=no,status,resizable=yes,addressbar=no');<");
        sb.Append("/script>");
        ScriptManager.RegisterStartupScript(Page, GetType(), "OpenWindow", sb.ToString(), true);
    }
}

The above code is not opening any window. 上面的代码没有打开任何窗口。

You don't want to use RegisterStartupScript in this case, you want to add an onclick handler for your button and you want to do it in RowDataBound instead: 在这种情况下,您不想使用RegisterStartupScript,而是要为按钮添加一个onclick处理程序,而要在RowDataBound中执行此操作:

protected void gvKeys_RowDataBound(object sender, GridViewRowEventArgs e)
{

  if (e.Row.RowType == DataControlRowType.DataRow)
  {

    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append("window.open('OverwriteConfiguration.aspx', 'PopUp',");
    sb.Append("'top=0, left=0, width=500, height=500, menubar=no,toolbar=no,status,resizable=yes,addressbar=no');<");

    LinkButton l = (LinkButton)e.Row.FindControl("lnkView");

    l.Attributes.Add("onclick", sb.ToString());

   }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM