how to open popup window through javascript in code behind( popup window should be aligned center)


I want to use javascript in code behind to open popup window.
I have Datalist inside which there is linkbutton. On click of linkbutton open popup window through javascript & that pop up window
should be aligned centraly.

Regards,
Mahesh
--------------------
click "Mark as Answer" on the post that helps you.
-2
maheshshinde9
9/16/2008 4:51:12 PM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 6 followers.

💬 3 Replies
👁️‍🗨️ 4084 Views



Friend,
Try this sample .
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
   
    <style>
    .blue
{
 background-color:Blue;
}
.green
{
 background-color:Green;
}
   
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    <asp:DataList ID="DataList1" runat="server" RepeatColumns="2" Width="129px"
        onitemdatabound="DataList1_ItemDataBound">
        <ItemTemplate  >
            <asp:Panel ID="Panel1" CssClass="blue" runat="server">
                <asp:LinkButton ID="LinkButton1" runat="server" >LinkButton</asp:LinkButton>
            </asp:Panel>
        </ItemTemplate >
    </asp:DataList>
    <script>
   
    function dowork(panelid)
    {
       var newwin =  window.open('WebForm435.aspx?panelid='+panelid);
       newwin.focus();
    }
    </script>
    </form>
</body>
</html>
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable table = new DataTable();
            table.Columns.Add("test");
            for (int i = 0; i < 10; i++)
            {
                DataRow dr = table.NewRow();
                dr["test"] = i.ToString();
                table.Rows.Add(dr);
            }
            this.DataList1.DataSource = table;
            DataList1.DataBind();
        }
        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            Panel panel = e.Item.FindControl("Panel1") as Panel;
            LinkButton btn = e.Item.FindControl("LinkButton1") as LinkButton;
            btn.Attributes.Add("onclick","dowork('"+panel.ClientID+"')");
            //Response.Write(e.Item.ClientID);
        }
    <form id="form1" runat="server">
    <div>
   
    </div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    </form>
</body>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["panelid"] = Request.QueryString["panelid"].ToString();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string sciprt = " var ele = window.opener.document.getElementById('"+ViewState["panelid"]+"'); ele.className ='green';window.close();";
            this.ClientScript.RegisterStartupScript(this.GetType(), "aaa", sciprt, true);
        }
Source refer here : http://forums.asp.net/p/1303667/2551754.aspx
Good luck!
 

Please Don't forget to click "Mark as Answer" on the post that helped you.
This can be beneficial to other community members reading the thread.
0
cv_vikram
9/16/2008 5:14:21 PM

Thank you for your reply. reply that you posted is reply to my past question.( means http://forums.asp.net/p/1303667/2551754.aspx )
Thanks once again.

Regards,
Mahesh
--------------------
click "Mark as Answer" on the post that helps you.
0
maheshshinde9
9/16/2008 5:48:35 PM

Try:
 
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
        string script;
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            LinkButton lb = (LinkButton)e.Item.FindControl(&quot;LinkButton1&quot;);
            if (lb != null)
            {
                script = &quot;window.open(&#39;Page.aspx&#39;);&quot;;
                lb.Attributes.Add(&quot;onclick&quot;, script);
            }
        }
}
  

Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
1
vinz
9/16/2008 5:50:25 PM
Reply:

Similar Artilces: