locked
ClientScript.RegisterStartupScript is not working in gridview RRS feed

  • Question

  • User1046245955 posted

    ClientScript.RegisterStartupScript is not working in gridview

    here's my code:

    <gridiview>

    <asp:TemplateField ShowHeader="False">
    <ItemTemplate>
    <asp:LinkButton ID="linkbtnedit" runat="server" Text="Print" CssClass="btn btn-success"
    OnClick="Button_PRT"  CausesValidation="False"
    CommandName="Select" OnClientClick="aspnetForm.target ='_blank';setTimeout('fixform()', 500);"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>

    </gridview>

    protected void Button_PRT(object sender, EventArgs e)
    {
    LinkButton btn = sender as LinkButton;
    GridViewRow row = btn.NamingContainer as GridViewRow;

    string idno = GridView1.DataKeys[row.RowIndex].Values[0].ToString();
    string srno = GridView1.DataKeys[row.RowIndex].Values[1].ToString();

    Session["IDNO"] = idno;
    Session["SRNO"] = srno;

    ClientScript.RegisterStartupScript(this.Page.GetType(), "", "window.open('page.aspx','Graph','height=400,width=500');", true);

    }

    Monday, December 12, 2016 12:46 PM

All replies

  • User475983607 posted

    What does not working mean exactly?  What do you expect to happen?  Have you tried debugging the code?  

    Does idno and srno contain the expected values.  What does page.aspx do?

    string idno = GridView1.DataKeys[row.RowIndex].Values[0].ToString();
    string srno = GridView1.DataKeys[row.RowIndex].Values[1].ToString();

    Monday, December 12, 2016 1:47 PM
  • User1046245955 posted

    after the user will click the linkbutton in gridview i just want to have a window pop up page

    Tuesday, December 13, 2016 5:19 AM
  • User1771544211 posted

    Hi paminchever,

    after the user will click the linkbutton in gridview i just want to have a window pop up page

    I test your code on my side, it works fine. Please check if the popup page is blocked by your browser. You can find how to configure web browsers to allow popup windows in the following link.

    https://www.isc.upenn.edu/how-to/configuring-your-web-browser-allow-pop-windows

    The result on my side:

    Best Regards,

    Jean

    Tuesday, December 13, 2016 6:03 AM