You must Sign In to post a response.
  • Category: ASP.NET

    Need to open in a new window.. in asp.net using c#

    i have a linkbuttion if i click the linkbutton i need to open in a new window
  • #762242
    Hi

    You can try this code which is i mention below just copy paste in your project .

    I have gridview link and separate link added for this.


    Client Side


    <style type="text/css">

    .modalShow
    {
    background-color: Black;
    filter: alpha(opacity=40);
    opacity: 0.4;
    }
    .modalPopupWindows
    {
    background-color: #FFFFFF;
    width: 300px;
    border: 3px solid #0DA9D0;
    }
    .modalPopupWindows .header
    {
    background-color: #2FBDF1;
    height: 30px;
    color: White;
    line-height: 30px;
    text-align: center;
    font-weight: bold;
    }
    .modalPopupWindows .body
    {
    min-height: 50px;
    line-height: 30px;
    text-align: center;
    padding:5px
    }

    .modalPopupWindows .button
    {
    height: 23px;
    color: White;
    line-height: 23px;
    text-align: center;
    font-weight: bold;
    cursor: pointer;
    background-color: #9F9F9F;
    border: 1px solid #5C5C5C;
    }

    </style>

    </head>
    <body>
    <form id="form1" runat="server">
    <AjaxToolkits:ToolkitScriptManager ID = "ToolkitScriptManager1" runat = "server"></AjaxToolkits:ToolkitScriptManager>

    <asp:GridView ID="GrdData1" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:BoundField DataField = "EMPID" HeaderText = "EMPID ID" />
    <asp:BoundField DataField = "EMPNAME" HeaderText = "EMPNAME" />

    <asp:TemplateField ItemStyle-Width = "30px" HeaderText = "EMPID">
    <ItemTemplate>
    <asp:LinkButton ID="lnkEditRecord" runat="server" Text = "Edit" OnClick="lnkEditRecord_Click"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>

    <asp:LinkButton Text="Show Popup" ID = "lnklnk" runat="server" />
    <AjaxToolkits:ModalPopupExtender ID="mpe" runat="server" PopupControlID="pnlPopup" TargetControlID="lnklnk"
    CancelControlID="btnClose" BackgroundCssClass="modalShow">
    </AjaxToolkits:ModalPopupExtender>
    <asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopupWindows" Style="display: none">
    <div class="header">
    Header
    </div>
    India Is Big Country....
    <div class="footer" align="right">
    <asp:Button ID="btnClose" runat="server" Text="Close" CssClass="button" />
    </div>

    </asp:Panel>

    </form>



    Server Side


    protected void Page_Load(object sender, EventArgs e)
    {
    DataTable dt = new DataTable();
    dt.Columns.Add("EMPID");
    dt.Columns.Add("EMPNAME");
    DataRow dr;
    dr = dt.NewRow();
    dr[0] = 1001;
    dr[1] = "Jayakumar";
    dt.Rows.Add(dr);

    GrdData1.DataSource = dt;
    GrdData1.DataBind();
    }

    protected void lnkEditRecord_Click(object sender, EventArgs e)
    {
    mpe.Show();
    }


    I have attached snapshot given below check them

    If you fixed in your issue from my answer

    Dont forgot select as best answer

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment

  • #762260
    Hi selvi,

    You need to show the popup window when you click on link button inside gridview right..?

    You can achieve this by using AJAX Modal popup extender control, refer below link here I explained how to open popup window when we press a button,

    http://www.dotnetspider.com/resources/46217-ModalPopupExtender-with-Yes-No-options-without-postback.aspx

    I hope this will helpful to you..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762261
    Hello Selvi,

    I have used Button, but you can use Link Button instead of button with same code.

    Refer the below example :

    HTML Markup :

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <style type ="text/css">
    .modalBackground
    {
    background-color:silver;
    filter: alpha(opacity=60);
    opacity: 0.6;
    }

    .modalPopup
    {
    background-color:White;
    border: 1px solid #4C3C1B;
    padding: 5px;
    }
    </style>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
    Name : <asp:TextBox ID="TextBoxName" runat="server" Enabled="False"></asp:TextBox><br />
    Class : <asp:TextBox ID="TextBoxClass" runat="server" Enabled="False"></asp:TextBox><br /><br />

    <asp:Button ID="ButtonShowDialog" runat="server" Text="Show Dialog" ToolTip="Show student details"/>
    <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="ButtonShowDialog" BackgroundCssClass="modalBackground" Enabled="true" PopupControlID="Panel1" Drag="false"></cc1:ModalPopupExtender>
    <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Select</asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
    <asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
    </Columns>
    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
    <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
    <SortedAscendingCellStyle BackColor="#FDF5AC" />
    <SortedAscendingHeaderStyle BackColor="#4D0000" />
    <SortedDescendingCellStyle BackColor="#FCF6C0" />
    <SortedDescendingHeaderStyle BackColor="#820000" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [StudentDetails]"></asp:SqlDataSource>
    <br />
    <asp:Button ID="ButtonClose" runat="server" Text="Close" OnClick="ButtonClose_Click"/>
    </asp:Panel>
    </div>
    </form>
    </body>
    </html>

    Code - Behind :

    private void closepopup()
    {
    ModalPopupExtender1.Hide();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
    TextBoxName.Text = null;
    TextBoxClass.Text = null;
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
    GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
    int index = gvRow.RowIndex;

    TextBoxName.Text = GridView1.Rows[index].Cells[1].Text;
    TextBoxClass.Text = GridView1.Rows[index].Cells[2].Text;
    closepopup();
    }

    protected void ButtonClose_Click(object sender, EventArgs e)
    {
    closepopup();
    }

    See the attached file. It's an output of above code.

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment


Sign In to post your comments