弹出窗口不会打开行命令

时间:2014-11-26 16:07:41

标签: javascript c# asp.net

我有一个ajaxcontrol,下面是以下标签面板。它包含一个具有链接按钮的网格视图。我试图用后面的代码中的表单打开一个新窗口但是当我单击链接按钮时,我被重定向到我的tabcontrol中的第一个面板,它看起来不像回发。

<ajaxcontrol:TabPanel ID="TabPnlDependents" runat="server">
<HeaderTemplate>
Dependents
</HeaderTemplate>
<ContentTemplate>
  <table>
        <tr>
            <td>
                 <asp:GridView ID="DependentsGridView" DataSourceID="SqlDependentsGridView" AutoGenerateColumns="false" runat="server" DataKeyNames="PerId,PersonId" OnRowCommand="DependentsGridView_RowCommand">
                    <Columns>
                         <asp:TemplateField HeaderText="Dependent ID">
                             <ItemTemplate>
                                     <asp:LinkButton runat="server" ID="BtnDepenedentForm" Text='<%# Bind("PersonId") %>' CommandName="OpenDependentForm" CommandArgument='<%# DataBinder.Eval(Container,"RowIndex") %>' />
                             </ItemTemplate>
                          </asp:TemplateField>
                          <asp:BoundField DataField="FullName" HeaderText="Name" />
                          <asp:BoundField DataField="Gender" HeaderText="Gender" />
                         <asp:BoundField DataField="RelationToMain" HeaderText="Relation" />
                   </Columns>
                </asp:GridView>
            </td>
       </tr>
   </table>

  

后面代码中LinkBut​​ton Row Command的事件如下:

protected void DependentsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "OpenDependentForm")
            {
                int index = Int32.Parse(e.CommandArgument.ToString());
                GridViewRow SelectedRow = DependentsGridView.Rows[index];

                String RefId = DependentsGridView.DataKeys[index].Values[0].ToString();
                String DependentId = DependentsGridView.DataKeys[index].Values[1].ToString();

                string url = "DependentForm.aspx?DependentId=" + DependentId + "&PerId=" + PerId;
                string script = "window.open('" + url + "', 'popup_window1','width=700, height=700, left=50, top=100, resizable=yes');";
                this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "script", script, true);
            }
        }

但是当我尝试直接在我的页面上打开url时,它打开了。

2 个答案:

答案 0 :(得分:0)

如果您要创建一个包含Itemtemplate的链接,只需添加一个javascript onclick事件即可打开弹出窗口。在这种情况下无需回发。

您可能需要在windows.open之后立即调用event.preventDefault()来取消回发。

类似的东西:

<asp:LinkButton id="BtnDepenedentForm" runat="server" onClientClick="window.open('DependentForm.aspx?DependentId=<%# Bind("PersonId") %>&PerId=<%# Bind("PersonId") %>');event.preventDefault();" ....

答案 1 :(得分:0)

string url =&#34; MU2DashboardDetail.aspx?MM =&#34; + MainMeasure;             string script =&#34; window.open(&#39;&#34; + url +&#34;&#39;,&#39; DashboardDetails&#39;,&#39; width = 1200,height = 500,left = 80,top = 100,resizable = yes&#39;);&#34 ;;             ScriptManager.RegisterStartupScript(this,this.GetType(),&#34; java1&#34;,script,true);