UrlReferrer is null after clicking hyperlink control - asp.net

I've got my asp:hyperlink control on a page named "Items"
<asp:HyperLink ID="btnAddToCart" Text="Add To Cart" runat="server" Visible="False" />
The codebehind is setting the NavigateUrl for the hyperlink control.
Dim btnAddToCart As HyperLink = CType(e.Item.FindControl("btnAddToCart"), HyperLink)
btnAddToCart.NavigateUrl = "http://fake.com/checkout?productid=123"
When I click the button, the "Checkout" page loads. However, when I check the Request object in my .NET code, the Request.UrlReferrer is empty... and none of the other properties provide detail that the previous page was "Items".
Is my mistake horribly obvious, or is there some other way I should be redirecting so that the UrlReferrer gets populated?

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

Buttons stop working when UserControl is added to page

I have a content page with a UserControl. When the UserControl is added to the page, all of the buttons, including buttons in the master page, stop working. If I remove the UserControl the buttons start working again. By not working, I mean if you click them nothing happens at all, no postback. Some buttons still work, such as the GridView header labels which sort the columns. These cause postback, but nothing else.
The only elements in the UserControl are a fieldset containing a html label, containing a RequiredFieldValidator and a TextBox.
This solution here mentions solving a similar problem by including a !isPostBack check to the Page_Load, but what is included? My UserControl Page_Load event is currently empty.
Update
User Control .ascx
<%# Control Language="C#" AutoEventWireup="true" CodeFile="StaffEditFields.ascx.cs"
Inherits="StaffEditFields" %>
<fieldset>
<label>
Username
<asp:RequiredFieldValidator ID="rfdUser" runat="server" Display="Static"
ControlToValidate="txtUser" />
<br />
<asp:TextBox ID="txtUser" runat="server" CssClass="fvBox" Text='<%# Bind("Username") %>' />
</label>
</fieldset>
Update 2
Removed the fieldset and nothing changed, but when I removed the RequiredFieldValidator the page began to function normally. Now I need to ask how to keep the RequiredFieldValidator and allow the UserControl to function properly?
I figured it out. The problem is the RequiredFieldValidator is not set to validate to any specific button, therefore it will try to validate on ANY button click on the page. I also failed to set any button to CausesValidation="true".
The solution is then to set a validation group for the RequiredFieldValidator and set a button inside or outside the UserControl to CausesValidation="true" and ValidationGroup=[group].

switch masterpage button default button property in ASP.NET

I'm developing an ASP.NET web app (C#, VS2010), I have a master page which has a button (search button) and a textbox, when I press enter, this search button executes, but I don't want this master page search button to work when I'm in my login page. In my login page I have two textboxes and another button (login button), I want this login button to work as default button (execute with enter key) when I'm in login page. Of course I've not used any javascript or DefaultButton property at all
how can I disable masterpage button enter key in my login page?
You need to define a DefaultButton around each area you want default buttons, it will then use the part of the form that has focus:
<asp:Panel id="SearchPanel" runat="server" DefaultButton="Search" >
<asp:Button id="Search" runat="server" Text="Search" />
<asp:Panel>
<asp:Panel id="LoginPanel" runat="server" DefaultButton="Login" >
<asp:Button id="Login" runat="server" Text="Login" />
<asp:Panel>
In your login Page get a reference to Master Page button control and then disable it.
Button b = Master.FindControl("ButtonID");
b.Enable= false;
To change default buton of master page change it's default button in master page codebehind
form1.DefaultButton = "New button ID";
oR from login page codebehind
Form.DefaultButton = "New button ID";

ASP.NET Button Click causes a Postback *and* a "GET" - why?

I have code that seems to defy explanation. There are a couple of pages that do some data maintenance in our web application (VB.net codebehind). One works as expected, the other has a problem.
They both have an Ajax Tab Container to group the appropriate parts of the data. When I hit the 'Save' button, I want the page to remember what the active tab was. In the first page, there's no problem. I get the postback, go through the Page_Load and everything works as expected.
For some reason, on the second page, when I click the Save button, which is defined exactly the same as on the first page, I get the "POST" that I expect (Request.RequestType = "POST") but then Page_Load gets fired AGAIN with Page.IsPostback being "False" (Request.RequestType = "GET") - like I just clicked into the page.
The button markup is simple the only difference is that one is in a table and the second is in it's own <div>
:
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
<asp:Button ID="btnSave" runat="server" Text="Save" Width="2in" />
</asp:TableCell>
<center>
<asp:Button ID="btnSave" runat="server" Text="Save" Width="4in" Height="0.33in" />
</center>
The markup at the top of the pages is identical - just the required properties with AutoEventWireup and EnableEventValidation as "False" and MaintainScrollPositionOnPostback as "True".
I can't understand why these two pages are giving me such difference results. With the .aspx markup being so similar, it's easy to spot any differences. How can I figure out where this phantom "GET" is coming from?

Resources