Using LinkButton PostbackUrl - new window/tab needed to open - asp.net

Im posting and redirecting to a third party by setting the PostBackUrl property on a LinkButton.
My problem is that I want this to open in a new tab but target="_blank" doesnt do anything here.
<asp:LinkButton ID="hlApplication" runat="server" Text="Start your application" aria-describedby="information" target="_blank" OnClientClick="this.disabled=true;" UseSubmitBehavior="false"/>
hlApplication.PostbackUrl ="http://externalurl";
Any ideas how I can do this?

Try this:-
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='http://www.google.com' Target="_blank">Google </asp:HyperLink>

In this instance, we had to have a hyperlink that opened a new tab that contained the form. This form is automaticaly posted by Javascript and the user taken to their destination. This was the only way we could get this to work

Related

on every postback page opens in a new tab

I have a weird problem in my page. I have a button called Print. I wanted report should come in a new tab, so i wrote some javascript on button's onClientClick. Which works great with no problem at all.
But problem starts now when user comes back on original page again, now here i have several controls which cause postback. Say for example its a dropdownlist. so whenever user changes dropdown item it causes postback which is fine but everytime it opens a new tab on every postback.
hope I am clear in question...
Any help??
Here is a code:
<asp:Button ID="btnshow" runat="server" Text="Show" Font-Bold="true" ForeColor="Black" Width="90px" OnClick="btnshow_Click" OnClientClick ="document.forms[0].target = '_blank';"/>
The issue is document.forms[0].target='_blank' is setting the target on the form not the individual button so a postback triggered by any control will open in a new tab.
You should use a HyperLink control instead of the Button control. The HyperLink control has a Target property which allows you to specify how the link should be opened.
Below is an example taken from the HyperLink documentation. This will render an anchor tag with target="_blank".
<asp:HyperLink ID="lnkPrint" NavigateUrl="http://www.microsoft.com" Text="Print" Target="_blank" runat="server" />

Adding a click event to a Hyperlink displayed in ListView VB.NET ASP.NET

Is there a way to add a click event to a Hyperlink tag that's render in ListView?
Basically, I have a HyperLink tag that generates a link dynamically and it opens up to a new tab when users click on it. At the same time, when the user click on it, I want to post a text or make the text label visible. Sample code below:
<asp:ListView ...>
<ItemTemplate>
<asp:Label ID="Msg" Text="*You have already accessed this link*" runat="server" Visible="false"/>
<asp:HyperLink ID="label1" NavigatUrl='<%#Eval("Link")%>'Target="_blink" text="Click Link" runat="server"></asp:HyperLink>
<//ItemTemplate>
</asp:ListView>
You can use QueryString. Add the link with a Query Parameter on it and then -
If IsPostBack=True then 'Check if the page is reloading [Because when you clik on the link with the same link, it will reload the page]
'Considering the QueryString will be like - "yourdomain/default.aspx?item=1"
'Check for QueryString
Dim s_ItemId As String = Request.QueryString("item")
if s_ItemId<>"" then
'Do whatever you want
End If

User response.redirect to open link in new tab or window

I want to use response.redirect to open page in new window or tab. I tried following things.
1)
<asp:ImageButton ID="createPanelBtn" runat="server" ImageUrl="~/Resources/User.ico" Height="23px" ToolTip="Create Interviewer Panel" CommandName="createPanelBtn"
CommandArgument=" <%#((GridViewRow)Container).RowIndex %>" Width="20px" OnClientClick="aspnetFrom.target='_blank';"/>
2)
Response.Write("<script>window.opem('~/HR Administrator/ConfirmationEntryForm.aspx?VacId=" + strVacId + "&CompId=" + strCompId + "&DeptId=" + strDeptId+")'</script>");
Response.End();
In none of the cases, I am able to achieve the goal. Please show me some way to do so...
A better way of writing point (2) in your question which I suggest is use the literal control. Its the cheapest and easiest way to include/exclude scripts on web page. Like for e.g. say I have a login page where the user has to enter his credentials. If he enters the wrong credentials, the page should postback and give an alert message. For this I'd simply set the literal control which contains the script code to visible (Visble=True).
<asp:Literal ID="ltrlInvalidLogon" runat="server" Visible="false">
<script type="text/javascript">
alert('Invalid LogonID or Password provided.');
</script>
</asp:Literal>
<asp:LinkButton ID="lnkbtnvd" runat="server" Text="View Details" OnClientClick="javascript:window.open('viewclient.aspx', 'windowname', 'width=400,height=200,scrollbars=yes');" ></asp:LinkButton>
Use your parameters
<asp:ImageButton id="createPanelBtn" runat="server" OnClientClick="javascript:window.open('page.aspx?ruerystring', 'windowname', 'width=600,height=600,scrollbars=yes');" />
and for other parameter of the window.open function check below link
http://www.w3schools.com/jsref/met_win_open.asp
http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
I found a solution that works perfectly! It's a workaround but worked for me.
set the onclientclick property of the button that opens the new age as follows:
onclientclick="window.document.forms[0].target='_blank'; setTimeout(function(){window.document.forms[0].target='';}, 500);"
It uses a setTimeout to revert the change back to what it was!
Hopefully this can help someone!

link button property to open in new tab?

In my application I have some link buttons there but when I right click on them I cannot (they are in disable mode) find the menu items Open in new tab or Open in new window.
How do I show those menu items?
Code example:
<asp:LinkButton id="lbnkVidTtile1" runat="Server" CssClass="bodytext" Text='<%#Eval("newvideotitle") %>' />
From the docs:
Use the LinkButton control to create a hyperlink-style button on the Web page. The LinkButton control has the same appearance as a HyperLink control, but has the same functionality as a Button control. If you want to link to another Web page when the control is clicked, consider using the HyperLink control.
As this isn't actually performing a link in the standard sense, there's no Target property on the control (the HyperLink control does have a Target) - it's attempting to perform a PostBack to the server from a text link.
Depending on what you are trying to do you could either:
Use a HyperLink control, and set the Target property
Provide a method to the OnClientClick property that opens a new window to the correct place.
In your code that handles the PostBack add some JavaScript to fire on PageLoad that will open a new window correct place.
Here is your Tag.
<asp:LinkButton ID="LinkButton1" runat="server">Open Test Page</asp:LinkButton>
Here is your code on the code behind.
LinkButton1.Attributes.Add("href","../Test.aspx")
LinkButton1.Attributes.Add("target","_blank")
Hope this will be helpful for someone.
Edit
To do the same with a link button inside a template field, use the following code.
Use GridView_RowDataBound event to find Link button.
Dim LB as LinkButton = e.Row.FindControl("LinkButton1")
LB.Attributes.Add("href","../Test.aspx")
LB.Attributes.Add("target","_blank")
try by Adding following onClientClick event.
OnClientClick="aspnetForm.target ='_blank';"
so on click it will call Javascript function an will open respective link in News tab.
<asp:LinkButton id="lbnkVidTtile1" OnClientClick="aspnetForm.target ='_blank';" runat="Server" CssClass="bodytext" Text='<%# Eval("newvideotitle") %>' />
This is not perfect, but it works.
<asp:LinkButton id="lbnkVidTtile1" runat="Server"
CssClass="bodytext" Text='<%# Eval("newvideotitle") %>'
OnClientClick="return PostToNewWindow();" />
<script type="text/javascript">
function PostToNewWindow()
{
originalTarget = document.forms[0].target;
document.forms[0].target='_blank';
window.setTimeout("document.forms[0].target=originalTarget;",300);
return true;
}
</script>
LinkButton executes HTTP POST operation, you cant change post target here.
Not all the browsers support posting form to a new target window.
In order to have it post, you have to change target of your "FORM".
You can use some javascript workaround to change your POST target, by changing form's target attribute, but browser will give a warning to user (IE Does), that this page is trying to post data on a new window, do you want to continue etc.
Try to find out ID of your form element in generated aspx, and you can change target like...
getElementByID('theForm').target = '_blank' or 'myNewWindow'
When the LinkButton Enabled property is false it just renders a standard hyperlink. When you right click any disabled hyperlink you don't get the option to open in anything.
try
lbnkVidTtile1.Enabled = true;
I'm sorry if I misunderstood. Could I just make sure that you understand the purpose of a LinkButton? It is to give the appearance of a HyperLink but the behaviour of a Button. This means that it will have an anchor tag, but there is JavaScript wired up that performs a PostBack to the page. If you want to link to another page then it is recommended here
that you use a standard HyperLink control.
It throws error.
Microsoft JScript runtime error: 'aspnetForm' is undefined
<asp:LinkButton ID="LinkButton1" runat="server" target="_blank">LinkButton</asp:LinkButton>
Use target="_blank" because It creates anchor markup. the following HTML is generated for above code
<a id="ctl00_ContentPlaceHolder1_LinkButton1" target="_blank" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$LinkButton1','')">LinkButton</a>

how to navigate for a new window[IE] using datalist control

i using a datalist control i am binding with hyperlink control
<asp:Hyperlink ID="lbURL" runat="server" Text='<%#
Eval("URL") %>' />
so now this hyperlink would contain an url that points to some web site so once user click on this link a new IE window should be opened like if the url contains" https://stackoverflow.com/questions/ask", yahoo.com any thing like is
so once user clicks open the web site
any help would be great . looking forward for a solution
thank you
I think you are looking for the target="_blank" option.
<asp:Hyperlink ID="lbURL" runat="server" target="_blank" Text='<%# Eval("URL") %>' />
w3schools reference

Resources