ASP.NET - asp:hyperlink window properties

Asked By asif hameed on 06-Jan-11 01:26 PM
Hi All:

I have an asp.net page with repeater. inside it I have a item template. I have a Hyper link :

 <asp:HyperLink ID="hpErrorDetails" runat="server" Visible="false" onclick="myWindow=window.open('/','','width=200,height=100;toolbar=no')">Details ...</asp:HyperLink>

Inside C# : 

I have this:

 hpErrorDetails.NavigateUrl = string.Format("automatedtesterror.aspx?id={0}", automatedTestRun.AutomatedTestRunId);

I want to open in new window and want that newly opened window is without toolbar and  scrollbar. but I m getting error.

Regards,
Asif Hameed
anil soni replied to asif hameed on 06-Jan-11 01:32 PM
setting NavigateUrl will set href attribute of the anchor. you should instead attach the onclick attribute for each hyperlink as given below

 <asp:HyperLink ID="hpErrorDetails" runat="server" Visible="false" NavigateUrl="#">Details ...</asp:HyperLink>

In C# (Code Behinnd)


hpErrorDetails.Attributes.Add("onclick","myWindow=window.open('"+string.Format("automatedtesterror.aspx?id={0}", automatedTestRun.AutomatedTestRunId+"','','width=200,height=100;toolbar=no')");


asif hameed replied to anil soni on 06-Jan-11 01:56 PM
Hi anil:

I tried this code. It opens two windows. one for JavaScript and one using asp.net.

  <asp:HyperLink ID="hpErrorDetails" runat="server" Visible="false" NavigateUrl="#">Details ...</asp:HyperLink>

 hpErrorDetails.Attributes.Add("onclick","myWindow=window.open('"+string.Format("automatedtesterror.aspx?id={0}", automatedTestRun.AutomatedTestRunId+"','','width=500,height=500;toolbar=no')"));

Regards,
Asif Hameed


anil soni replied to asif hameed on 06-Jan-11 02:00 PM
make sure you have set NavigateUrl = ""# it will prevent opening the second link....

or you can try it like this

<asp:HyperLink ID="hpErrorDetails" runat="server" Visible="false" >Details ...</asp:HyperLink>

 hpErrorDetails.NavigateUrl = "javascript: myWindow=window.open('"+string.Format("automatedtesterror.aspx?id={0}", automatedTestRun.AutomatedTestRunId+"','','width=500,height=500;toolbar=no')";
asif hameed replied to anil soni on 06-Jan-11 02:02 PM
I tried both tricks but same thing happening. tow windows opening.
asif hameed replied to anil soni on 06-Jan-11 02:11 PM
hi anil: 

sorry about that. I was calling navigateurl twice. Thanks for the help.

Regards,
Asif Hameed