Click here to Skip to main content
15,878,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Friends,

I have a gridview. For each row in gridview, i have a linkbutton. When we click on that link then it needs to open a popup window (already exsting page need to show as popup).
I have written this in code behind like below.

It is working fine in IE9 but getting error in IE8.

--> when i click on the link in gridview, it should close the already exsting popup & needs to open popup again with the new id.

Please help me asap..



C#
protected void dgPO_EditCommand(object source, DataGridCommandEventArgs e)
    {
        try
        {
            string strInvoiceID = e.Item.Cells[0].Text.ToString();
            string url;
            url = "./Invoice.aspx?InvoiceID=" + strInvoiceID.ToString();
            Session["url"] = url;
            string winFeatures = "toolbar=no,status=no,menubar=no,location=center,scrollbars=yes,resizable=no,height=650,width=825";
            ClientScript.RegisterStartupScript(this.GetType(), "newWindow", string.Format("<script type='text/javascript'>var popup=window.open('{0}', 'yourWin', '{1}'); popup.focus();</script>", url, winFeatures));

        }
        catch (Exception ex)
        {
            lblstatus.Text = ex.Message.ToString();
        }
    }
Posted
Updated 17-Jul-12 2:44am
v2

Hi,
Try this:
C#
// open a pop up window at the center of the page.
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( '39;your_page.aspx?InvoiceID='" + strInvoiceID.ToString();+"', null, 'height=700,width=760,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);


--Amit
 
Share this answer
 
Comments
kishorekke 17-Jul-12 8:52am    
Hi friend thanx for your solution. I want always focus on the popup.
if i use ..
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( '39;your_page.aspx?InvoiceID='" + strInvoiceID.ToString();+"', null, 'height=700,width=760,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' ).focus();", true);

This is working in IE9.0 but getting error in IE8.0
Please suggest me, it should work on ie8 also.
Thanks
Kishore
hi,

please check below url

Popup window for the GridView[^]

Thanks.
 
Share this answer
 
v2
C#
string url = Invoice.aspx?InvoiceID=" + strInvoiceID.ToString() + "&";
 string str = Guid.NewGuid().ToString();
 str = str.Replace('-', '0');
 str = 'w' + str;
 System.Text.StringBuilder sb = new System.Text.StringBuilder();
 sb.Append(@"&lt;script language='javascript'>");
 sb.Append(@"PopWin('" + url + "','" + str + "', 'CallingFormName.aspx', '', '1024', '620');");
 sb.Append(@"</script>");
 System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "JCall1", sb.ToString(), false);

// Write following function in script block of .aspx page

function PopWin(varURL, varWindowName, varCaller, varKeyId, varWidth, varHeight) {
    var objTransparent = document.getElementById("Transparent");
    var height = document.body.clientHeight + 'px';
    document.documentElement.scrollTop = 0;
    if (navigator.appName == "Microsoft Internet Explorer")
        objTransparent.style.height = "100%";
    else
        objTransparent.style.height = height;

    objTransparent.style.width = "100%";

    objTransparent.style.visibility = 'visible';

    var varLeft = (screen.width / 2) - (varWidth / 2);
    var varTop = (screen.height / 2) - (varHeight / 2);

    popupWindow = window.open(varURL + 'Caller=' + varCaller + '&Id=' + varKeyId + '&ShowModal=1', varWindowName, 'width=' + (screen.width - 10) + 'px; height=' + (screen.height - 70) + 'px; top=' + 0 + '; left=' + 0 + '; location=0 ;resizable=1; scrollbars=1');

}
 
Share this answer
 
look these links
Article1[^]
Article2[^]
 
Share this answer
 
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
LinkButton lknbtn = (LinkButton)e.CommandSource;
string str = lknbtn.Text;
Session["msg"] = str;
string strmsg = Session["msg"].ToString();
string url = "messagedisplay.aspx";
string winFeatures = "toolbar=no,status=no,menubar=no,location=center,scrollbars=yes,resizable=no,height=650,width=825";
ClientScript.RegisterStartupScript(this.GetType(), "newWindow", string.Format("<script type='text/javascript'>var popup=window.open('{0}', 'yourWin', '{1}'); popup.focus();</script>", url, winFeatures));
}

Try these code, bind your message to textbox in a new popup window

you add your code to gridview rowcommand
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900