Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I am using the following code to open random number of pages based on GridView CheckBox Checked Status but It only opens the last page.

MIDL
string script = "<script>";
            foreach (GridViewRow row in gvM16Deductions.Rows)
            {
                chk = (CheckBox)row.FindControl("chkDeductionType");
                if (chk.Checked)
                {
                    string url = "../../Default5.aspx?m=" + cmbSDURN.SelectedValue + "&d=" + chk.ToolTip;
                    script += "window.open('"+url+"','window','toolbar=no,menubar=no,resizable=no,directories=no');";
                    //ClientScript.RegisterClientScriptBlock(typeof(string), "openPage" + chk.Text, "javascrit: openForm('" + cmbSDURN.SelectedValue + "','" + chk.ToolTip + "');");
                }
            }
            script += "</script>";
            ClientScript.RegisterClientScriptBlock(this.GetType(), "openPage", script);


What am I doing wrong?
I can't open all pages, the script from page source shows every thing is ok, but I dont know why only the last page opens?
One more interesting thing, if I give window.open('pageadddress+querystring') then it opens all pages, but I want to open it with param.
Posted
Updated 4-Jan-11 21:52pm
v2
Comments
Dalek Dave 5-Jan-11 3:52am    
Edited for Grammar and Readability.

what am i doing wrong which i can't open all pages, the script from page source shows every thing is ok, but I dont know why only the last page opens?
This is because of the 2nd parameter in the Window.Open method.
Second parameter is 'name' of the window. Since you are using same name for all the windows (fixed name here), all open into same one and thus the last one persists.

Look at the details here: MSDN: Window.Open[^]

Resolution: Change the name of the window everytime you form the script. Append an integer or any other way you find easy.
 
Share this answer
 
Comments
Abdul Rahman Hamidy 5-Jan-11 3:39am    
thank you very much, You solved my problem, Appreciated!!!
Sandeep Mewara 5-Jan-11 3:43am    
Glad it helped! :)
Dalek Dave 5-Jan-11 3:52am    
Good answer.
I don't have an specific idea, but you can try this by changing to your code.

            foreach (GridViewRow row in gvM16Deductions.Rows)
            {
                chk = (CheckBox)row.FindControl("chkDeductionType");
                if (chk.Checked)
                {
string script = "<script>";                    
string url = "../../Default5.aspx?m=" + cmbSDURN.SelectedValue + "&d=" + chk.ToolTip;
                    script += "window.open('"+url+"','window','toolbar=no,menubar=no,resizable=no,directories=no');";
                    //ClientScript.RegisterClientScriptBlock(typeof(string), "openPage" + chk.Text, "javascrit: openForm('" + cmbSDURN.SelectedValue + "','" + chk.ToolTip + "');");

            script += "</script>";
            ClientScript.RegisterClientScriptBlock(this.GetType(), "openPage", script);
                }
            }
 
Share this answer
 
Comments
Sandeep Mewara 5-Jan-11 3:37am    
Check my answer Hiren!
Abdul Rahman Hamidy 5-Jan-11 3:41am    
thanks for your reply,as Sandeep Mewara stated the 2nd parameter in window.open was the problem, I am changing the param in loop and that solved my problem.
Hiren solanki 5-Jan-11 3:42am    
Great.
Dalek Dave 5-Jan-11 3:53am    
Good call, I think Sandeep beat you by seconds!

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