This question already has answers here:
link button property to open in new tab?
(8 answers)
Closed 3 years ago.
I have this linkbutton here...
<asp:LinkButton ID="linkButton" CssClass="Button" runat="server" target="_blank">Button Text</asp:LinkButton>
but the target blank does not work, it does not open the page in a new tab, it opens it in the same tab.
What Am I doing wrong?
There is an href, its gets assigned in the code behind like so
linkButton.PostBackUrl = "http://www.nfl.com";
but still the target blank does not work....
You can try this. Hope it helps:
<asp:LinkButton ID="linkButton" OnClientClick="window.document.forms[0].target='_blank';" runat="server">Button Text</asp:LinkButton>
linkButton.PostBackUrl = "http://www.nfl.com";
Below code works fine:
OnClientClick="window.document.forms[0].target='_blank';
In ASP.NET web forms a button, linkbutton, imagebutton or similar control actually just submits the underlying form. In order to open this in a new window you can modify the target property of the "form" using JavaScript. We also need to undo the modification after the click otherwise further button clicks will unintentionally target the new tab, which we can do using a setTimeout and blanking the target again.
<asp:LinkButton ID="uiNewTabExample" Text="PDF" OnClick="uiNewTabExample_Click" OnClientClick="window.document.forms[0].target = '_blank'; setTimeout(function () { window.document.forms[0].target = '' }, 0);"
runat="server" />
Related
This question already has answers here:
Tooltips for Button elements
(8 answers)
Closed 7 years ago.
I have this code on my project.
string="my string"
how i show this string on a button as a tool-tip. I want this to do programmatically. I want this to do in my code not the design.
i do my codings in asp.net with c# language
Here's how to add the tooltip programmatically
just get the id of the button
<asp:Button id="button1" Text="Submit" runat="server" />
in your code behind:
//do some code to retrieve data from database and store it to this variable
String tooltip = "some text";
button1.ToolTip = tooltip;
I am trying to right click on a LinkButton and open it in a new tab or seperate window page displays nothing. I found some solution for the use of Hyperlink button as it has property to set target to "_blank" but LinkButton has not any target attribue.
I want to use LinkButton instead of hyperlink button, its just because i can't set command arguement or command name on hyperlink button and can't fire an event on it.
<asp:LinkButton ID="lnkHeadingHindi" Text='<%#Patrika.Common.ConvertNews(Eval("strMainHeadingHin").ToString())%>' CommandArgument='<%#Eval("intNewsId") %>' runat="server"></asp:LinkButton>
It would be great if anybody has a solution and let me know in case of any concern.
Thanks !!
Based on the accepted answer to this question, if you want to perform a POST (such as a LinkButton does) but have the result open in a new window, you need to add target="_blank" to the form on the page, not the link itself.
Obviously you don't want to do this when you initially render the page, as everything that caused a postback would open in a new window.
Instead, try adding the following attribute to your LinkButton:
OnClientClick="$('form').attr('target', 'blank')"
This will dynamically set the form attribute just before the form is posted back by a click to the link.
Note that this doesn't give the right-click functionality you want, but it does work to open in a new window on a left-click.
If you don't have access to JQuery, you'll need to do something like
protected void Page_PreRender(object se, EventArgs e)
{
this.Page.Form.ID = "someUniqueID"; // unless your form already has an ID
yourLinkButton.OnClientClick =
"document.getElementById('" +
this.Page.Form.ClientID +
"').setAttribute('target', '_blank')";
}
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:
1) Use a HyperLink control, and set the Target property
2) Provide a method to the OnClientClick property
that opens a new window to the correct place.
3) In your code that handles the PostBack add some JavaScript to fire on PageLoad that will open a new window correct place.
If you like when click the link button,then open new window,
please see this
insert base tag like this
<head>
<base target="_blank" />
</head>
If you want to pass some information to the page using hyperlink, pass it in the url using QueryString.
<asp:HyperLink id="hyperlink1"
NavigateUrl="~/MyPage.aspx?intNewsId=10"
Text="ClickMe"
Target="_blank"
runat="server"/>
You can't have it both ways, you'll have to choose between:
1) the linkbutton executing some code in the current page
2) a hyperlink opening another page in a new window
I guess you want to have the linkbutton executing some code in the new page, but that's impossible.
or if u like use . anger tag
Just render an anchor with href set to appropriate url and set the target attribute to _blank it will open the url into new window
<a href="urlOfThePage" target="_blank" >Click me</a>
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Send data from one page to another in C# ASP.Net
Hi I am trying to send data from one page to another in asp.net I found various methods of doing so and am gona try a few to se how they work but I seem to be getting an error on my first attempt.Here is my code:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Go"
PostBackUrl="~/Default2.aspx" />
<br />
I am sending the data from Default.aspx to Default2.aspx.
At the Default2.aspx in the Page_Load method I wrote this to retrieve the data:
if (Page.PreviousPage != null)
{
string txtBox1 = ((TextBox)Page.PreviousPage.FindControl("TextBox1")).Text;
}
From what I read on MSDN this should work but I must be missing something because when I pres the button to send the data and Default2.aspx loads I get an error page that looks like this:
if you use master page for Default.aspx then Page.PreviousPage.FindControl doesn't work. Because when using masterpage, all controls in Default.aspx are placed in ContentPlaceHolder not directy in Form. So you can use below code:
Page.PreviousPage.Form.FindControl("yourContentPlaceHolderID").FindControl("TextBox1");
i assume you use masterpage. Otherwise your first code must work. In addition if you dont use masterpage and textbox is placed in PlaceHolder or Panel, your code won't work as well. FindControl doesnt recursively search in child container controls.
See the link. MSDN
Page.PreviousPage is only available when using Server.Transfer to redirect to a new page. If this is a standard GET or POST, or Response.Redirect then this code will not work.
From your previous page. Use Server.Transfer to be able to access the previous page data.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Lost Focus method for asp.net textbox?
i want to check the data entered by user on the client side.
it is necessary for me to use control.
is there any way so that i can check after client move on to the next input and i can check the data by javascript ?
<asp:TextBox ClientIDMode="Static" onblur="return userCheck(this.id)" onkeyup="return userCheck(this.id)"
ID="txtUserName" runat="server" Width="180"></asp:TextBox>
here i have used two events but i want to use only one.
You can do that with onblur event using javascript.
f.e something like that:
<asp:TextBox runat="server" onblur="Javascript:alert('1234');" />
For what you want to do, you can set the textbox to have AutoPostBack=True; any time the text in the box is changed and the box loses focus, it will post back to the page; you can use the TextChanged property, as well, if you don't want to post back, which will check to see if the text of the TextBox has been changed between posts.
Finally, you can bind the JavaScript onFocus and onBlur events to the textbox, and handle changes to its contents via JavaScript:
http://support.microsoft.com/default.asp…
Source: http://answers.yahoo.com/question/index?qid=1006040618831
<asp:LinkButton ID="lnkbtnMoreTagRules" runat="server"
CommandName='<%#Eval("Value")%>'
CommandArgument='<%# string.Format("{0}||||{1}", Eval("Tag"),
Eval("TagAppearance"))%>'
OnCommand="lnkbtnMoreTagRules_Command">Več pravil</asp:LinkButton>
I want to close current window tab and open new one.
How can i open a new window tab with linkbutton. target="_blank" not helping.
As link button is posted back, so it cannot be used for a GET request. instead use HyperLink Class
LinkButton works like a Button and does not have a Target attribute. Use a HyperLink instead and set the Target.
You need something like this
<asp:LinkButton id="LinkButton1" runat="server" onClientClick="window.open('http://asp.net');"
I doubt we have any foolprrof code to open link in tabs because most of the browser activities are totally under the control of users.
User can change thier browser settings in the way they wanted to behave.
There is nice discussion related to this in below thread, it will be interesting for you,
http://www.dynamicdrive.com/forums/archive/index.php/t-19843.html