Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir

I want that when a user click on template button of Grid View in asp .net a new browser should open. I have done the project but the problem is that when i am clicking on button for the first time new window is not opening and on second click it is working.Can you please solve the problem ? I have written the code below..
C#
protected void gvEmployer_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        
        if (e.CommandName =="cmdDetails")
        {
            int index =Convert.ToInt32(e.CommandArgument);
            Button btn = (Button)gvEmployer.Rows[index].FindControl("btnDetails");
            btn.Attributes.Add("onClick", "window.open('detailsofjobseeker.aspx', '', '', 'height=200,width=400'); return false");
        }
      
    }
Posted
Updated 21-Oct-11 4:08am
v2

1 solution

hi Sashibhusan Meher,

This is because you need to register the script once to DOM, Try doing the below things

write the window.open code in a javascript function
like

JavaScript
<script language="javascript">
function popUp()
{
window.open('detailsofjobseeker.aspx', '', '', 'height=200,width=400'); return false;
}
</script>


then in pageLoad()
write like this..

C#
protected void Page_Load(object sender, EventArgs e)
        {
         String name1 = "PopupScript";
         String text1 = "<script type=\"text/javascript\">popUp();";
         RegisterStartupScript(name1, text1);
        }


and while calling.. write like this

C#
btn.Attributes.Add("onClick", "popUp();");


it may work.

Thanks.
 
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