404 error on link button click to valid website address - asp.net

When a user clicks on this particular link button in question, I receive a 404 error in the browser. When I click the refresh button on the browser, the target website loads as normal. Any thoughts on what this might be? It's just a plain old .net link button:
<asp:LinkButton ID="lnkWhatAre" runat="server" ForeColor="#FF9999"
Style="text-decoration: none" CausesValidation="false"
PostBackUrl="http://www.targetsite.com/">WHAT ARE?</asp:LinkButton>

PostBackUrl causes page to perform POST request, not all target pages like it. If you simple mean to provide a navigation link you can use something like this instead:
<asp:HyperLink ID="lnkWhatAre" runat="server" ForeColor="#FF9999"
Style="text-decoration: none"
NavigateUrl="http://www.targetsite.com/">WHAT ARE?</asp:HyperLink>
"asp:HyperLink" is a server-side control, so you can still set all its properties in server-side code if needed. And it renders as a normal hyperlink - so it won't cause any problems redirecting.

Related

ASP.NET HyperLink

I have written an server side hyperlink which will redirect to 'landing.aspx' page. Below is the code
<asp:HyperLink ID="HyperLinkLT1" runat="server" Text="Link Text" NavigateUrl="landing.aspx"></asp:HyperLink>
This is working fine in chrome. Now the problem is when I run the project in Firefox and click on the link, I am getting a popup which says error and them the page is redirected. Below is the screen shot.
Can someone help me to identify and clear the problem.

asp button on click is fired on local machine but it does not fire on published server

I cannot understand why but I have a button inside a panel (attached to an Ajax Modal Popup Extender), This button onclick gets fired on local machinw but it does not work on the uploaded server online.
Do you know what might be causing this behaviour?
<asp:Button ID="btnUpsertCommodity" runat="server" Width="70" Text="Submit" OnClick="btnUpsertCommodity_Click" ValidationGroup="Commodity"/>
try setting CausesValidation property
see this for details
button CauseValidation
I encountered this error once. I'm explaining why -
Check the Page Directive of your aspx page. Here, the CodeFile="Mypage.aspx.cs" property points to the Codebehind file where the button_click event will be written. Sometimes, this codefile property contains a relative URL to the Codebehind file like this : CodeFile="~/Mypage.aspx.cs". This relative URLs does not work after Server Deployment and can't redirect a button click event to the corresponding Event Handler. Thats why, you will see the page, but clicking the button will yield nothing.
Ckeck if you have done the same. If so, just remove the ~/ part from your page directive.

ASP.NET Login control focus in FireFox

I am using the Login control. Just in FireFox, I am finding that I cannot click directly on the UserName field. I need to tab through all the other elements on that page. Just wondering if there is a work around to this issue?
<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false" OnLoggedIn="LoginUser_LoggedIn">
You can do this by adding the following code to the Page_Load method on your login page:
AppLogin.Focus();
this.Form.DefaultButton = "ctl00$BodyPlaceHolder$AppLogin$LoginButton";
This will also cause the "login" button to be clicked when you click enter.
Note: The full "path" (ctl100$BodyPlaceHolder...) may vary slightly depending on whether or not you're using master pages, panels, etc. You can simply view the element on the page in your favorite inspector and find the rendered name for the login button.
More details can be found at my blog here.

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>

Page not submitting in Firefox

I've a user control registered in an aspx page.
User control has a textbox and a submit button.
Ascx code of user control is placed under a asp:panel.
Using firefox, when user hits enter key, the page is not submitting to the server.However, this works fine in IE browsers.
Am i missing something here?
Try setting defaultbutton="urbuttonid" to the asp:panel
Set property DefaultButton="submitbtn" for asp:panel.
Replace submitbtn with your asp:button id.
Yea, what the others say. You've probably got a submit button earlier in the page that Firefox is associating you enter key press with.
Use:
<asp:panel .... DefaultButton="btSubmit">
<asp:textbox ... />
<asp:button id="btSubmit" ... />
</asp:panel>

Resources