Hi
I was trying to "simplify" the links on my website a little as at the moment I use all absolute links, so I thought that I would use the HTML tag <base href="htp://www.[mywebsite].co.uk">. I did this, then promptly changed all the links in my site from being absolute to relative. Everything appeared to be fine and I was happy that I hadn't made a back-up (oops!) until I noticed that my asp:linkbuttons and other postbacks no longer worked how I expected. What happened was that the page tried to post back to the specified base href, as opposed to the directory the page was in (using past-tense because I had to change everything back and upload again!), eg,
Base Url:
<base href="http://www.discover-the-bahamas.co.uk/" />
The relevant page was:
http://www.discover-the-bahamas.co.uk/ABA00/prices.aspx
But tried to post back instead to:
http:///www.discover-the-bahamas.co.uk/prices.aspx
I'm not sure if it makes a difference but the section of code which contains the linkbutton (and causes the postback) is all contained within a usercontrol (and controlbehind file for the user control), ie,
My [edited] prices.aspx page:
<%@ Page Language="
VB" %>
<%@ Register TagPrefix="DTW" TagName="Prices" Src="../commonfiles/prices.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Bahamas Holidays: Plan your Bahamas holiday from our extensive range of Bahamas accommodation and holiday options</title>
</head>
<body>
<form runat="server">
<DTW:PRICES id="pricePanel" runat="server"></DTW:PRICES>
</form>
</body>
</html>
My [edited] usercontrol:
<%@ Control Language="
VB" Inherits="DTW.PricesCodeBehind" Src="cbPrices.
vb" %>
<asp:DataList id="dlPrices" runat="server" DataKeyField="hr_Id" OnItemCommand="DataList_ItemCommand" OnItemDataBound="BindGrid" Width="95%">
<itemtemplate>
<asp:LinkButton id="btnDesc" runat="server" CommandName="select" CommandArgument='<%# Container.DataItem("hr_Id") %>'><h4 style="text-decoration:underline;"><%# DataBinder.Eval(Container.DataItem, "hr_Name") %></h4></asp:LinkButton>
</itemtemplate>
</asp:List>
My [edited] Code-behind:
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Text
Imports Microsoft.VisualBasic
Imports dataAccess
Namespace DTW
Public Class PricesCodeBehind : Inherits UserControl
Public data as New DataAccessComponent()
Public dlPrices As DataList
Sub Page_Load(Sender As Object, E As EventArgs)
If Not IsPostBack Then
dlPrices.DataSource = data.getRooms()
dlPrices.DataBind()
End If
End Sub
Sub DataList_ItemCommand(Sender As Object, E As DataListCommandEventArgs)
Dim cmd As String = E.CommandSource.CommandName
If cmd = "select" Then
dlPrices.SelectedIndex = 0
End If
dlPrices.DataSource = data.getRooms(E.CommandSource.CommandArgument)
dlPrices.DataBind()
btnViewAll.Visible = True
End Sub
End Class
End Namespace
As I've said, I'm now using all absolute paths again in my site, but I'd REALLY like to be able to use some kind of base url that I can specify once in the page (or web.config or at application level?) so that I don't have to use it in every single link. Does anyone know of a way that I can do this which won't adversely effect my postbacks?
Thanks so much.
Shane