-1

I got an ajaxcontrol with the following tab panel below. It contains a grid view having a Link Button. I'm trying to open a new window with the form in the code behind but when i click the Link Button I get redirected to the first panel in my tabcontrol, it doesn't look like a postback.

<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>

The event for the LinkButton Row Command in the code behind is as follows:

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);
            }
        }

However when i tried opening the url directly on my page it opened fine.

user3340627
  • 3,023
  • 6
  • 35
  • 80
  • 1
    try this in your browser `javascript:window.open("DependentForm.aspx?DependentId=1&PerId=2", "MsgWindow", "width=700, height=700, left=50, top=100, resizable=yes")`; – Dgan Nov 26 '14 at 16:17

2 Answers2

0

If you are creating a link with an Itemtemplate, simply add a javascript onclick event to open your popup. No need to do a postback in this case.

You might need to call event.preventDefault() right after windows.open to cancel the postback.

Something like:

<asp:LinkButton id="BtnDepenedentForm" runat="server" onClientClick="window.open('DependentForm.aspx?DependentId=<%# Bind("PersonId") %>&PerId=<%# Bind("PersonId") %>');event.preventDefault();" ....
  • This answer also provides a slightly different approach which worked for me: http://stackoverflow.com/questions/3829701/how-to-bind-javascript-function-with-onclientclick-event-with-eval – user3340627 Dec 07 '14 at 13:31
0

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

Jeb's
  • 386
  • 2
  • 10