Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I have created a popup window to be opened in Gridview.But i am unable get popup window for the first click, it appears for the second click.

The code as follows:
C#
int index = Convert.ToInt32(e.CommandArgument);
index = index % GridView1.PageSize;
GridViewRow row = GridView1.Rows[index];
Image img = (Image)row.FindControl("imgSMS");
               
img.Attributes.Add("onclick","window.open('http://localhost:50807/Admin/Default.aspx','_blank','toolbar=0,location=0,menubar=0,resizable=0,height=300,width=300');return false");

Need your help.
Thanking you all.
Posted
Updated 10-Jan-12 21:29pm
v2

Hi,

this is because you add the javascript at that first click. At the second click, the javascript is existing and therefore being executed. You have to add the script earlier (e.g. on binding). The easiest way though would be to add
that javascript to your markup.

Hope that helps

Forgot: In addition to that, you could run your script immediatly without using the onlick handler. Google for "asp.net javascript RegisterStartupScript" or write it to your response stream
 
Share this answer
 
v2
this code will be excuted on first click. So, the onclick attribute for the button will affect only from the second time. So, You add onclick attribute for the Image button on Row data bound event like this..

C#
// on row data bound event

 if(e.Row.RowType == DataControlRowType.DataRow)
 {
      Image img = (Image)e.Row.FindControl("imgSMS");
      img.Attributes.Add("onclick","window.open('Admin/Default.aspx','_blank','toolbar=0,location=0,menubar=0,resizable=0,height=300,width=300');return false");
 
 }


hope it works..
 
Share this answer
 
v2
Comments
srinivas vadepally 11-Jan-12 4:16am    
thank you karthik,
how to send the querystring with same url of javascript?

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