How to open html page in new browser tab in asp.net link button click event in c#

Posted by Sekar.C under ASP.NET on 3/6/2013 | Points: 10 | Views : 4614 | Status : [Member] | Replies : 2
Hi,
How to open html page in new browser tab in asp.net link button click event in c#.

Regards
Sekar.c



Responses

Posted by: Sakthi.Singaravel on: 3/6/2013 [Member] Silver | Points: 25

Up
0
Down
private void Browser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)

{
var webBrowser = (WebBrowser)sender;
if (webBrowser.Document != null)
{
foreach (HtmlElement tag in webBrowser.Document.All)
{
if (tag.Id == null)
{
tag.Id = String.Empty;
switch (tag.TagName.ToUpper())
{
case "A":
{
tag.MouseUp += new HtmlElementEventHandler(link_MouseUp);
break;
}
}
}
}
}
}


private void link_MouseUp(object sender, HtmlElementEventArgs e)
{
var link = (HtmlElement)sender;
mshtml.HTMLAnchorElementClass a = (mshtml.HTMLAnchorElementClass)link.DomElement;
switch (e.MouseButtonsPressed)
{
case MouseButtons.Left:
{
if ((a.target != null && a.target.ToLower() == "_blank") || e.ShiftKeyPressed || e.MouseButtonsPressed == MouseButtons.Middle)
{
AddTab(a.href);
}
else
{
CurrentBrowser.TryNavigate(a.href);
}
break;
}
case MouseButtons.Right:
{
CurrentBrowser.ContextMenuStrip = null;
var contextTag = new ContextTag();
contextTag.Element = a;
contextHtmlLink.Tag = contextTag;
contextHtmlLink.Show(Cursor.Position);
break;
}
}
}


Regards,
Singaravel M

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/7/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this code


<asp:LinkButton ID="link1" runat ="server" Text ="Click" OnClientClick ="Newop();"
onclick="link1_Click" ></asp:LinkButton>

<script>
function Newop() {
var open_link = window.open('', '_blank');
open_link.location = "somepage.htm";
}

</script>

Mark as Answer if its helpful to you

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response