tags:

views:

45

answers:

2

Hi,

I developed a web application, in that main page i used link buttons and write some code in link button click event, Problem is when i right click on the link buttons i am not finding open in new tab option in link buttons, how can i solve this problem can u help me please.

A: 

The LinkButton control acts like a button.

Use HyperLink control instead if you want to have the href behavior.

<asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink>


HyperLink1.Text = "Go to StackOverflow";
HyperLink1.NavigateUrl = "http://www.stackoverflow.com";
Lee Sy En
@Lee Sy En but how can i write code in hyperlink,
Surya sasidhar
Use NavigateUrl from code behind. I have edited my code.
Lee Sy En
This will work, but understand you lose the "click" event. As this renders as a regular anchor tag. @Surya - you can either have a LinkButton which has a click event and renders as "special" anchor tag (with an onclick), or you can have a Hyperlink which renders as a anchor tag with a href. You cannot have both a HREF and a server-side click (AFAIK).
RPM1984
@RPM1984 Yes you are right, we lose the "click" event.
Lee Sy En
A: 

I think what @jarrett meant in his comment is that the resulting html that a LinkButton control generates is a javascript: href, not an href to a url - it's something along the lines of javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$ContentPlaceHolder1$loginBtn", "", true, "", "", false, true))

If you want the html output of a standard anchor tag/HyperLink (and the corresponding client browser behavior, including right-click to open in new tab or window) then use a standard anchor tag in your page <a href="pageurlhere.com">Link to your page</a>

If you need to be able to access the anchor tag from code-behind (assuming a Web Forms application) then you can add runat="server" to the tag and make it into a server-side Html Control, which is accessible to your code-behind.

cori
@RPM1984 makes a good point regarding the click event, which I didn't consider, so my answer obviously may not satisfy your needs.
cori