url aspx in composent ascx

143 views Asked by At

I have a web page search.aspx which list elements in a html table with some search criterias pass in url params. In this page, I call a pagination.ascx composant for pagination which is in a folder user_controls, and i pass the url for next and precedent pages. Did a simplified sample of my code :

search.aspx.cs :

public partial class search : IntranetPage
{
    protected override void OnInit(EventArgs e)
    {
        var paginationControl = (Pagination)LoadControl("UserControl/Pagination.ascx");
        paginationControl.urlNextPage = @"search.aspx?param1=test1&param2=test2";
        Pagination.Controls.Add(paginationControl);
    }
}

search.aspx (in folder UserControl/Pagination.ascx) :

<%@ Page Language="C#" MasterPageFile="IntranetCompil.master"
    AutoEventWireup="true" CodeBehind="search.aspx.cs" 
    Inherits="Back.search" ClientIDMode="Static" %>

<asp:Content ID="search" ContentPlaceHolderID="Main" runat="Server">
    <p>Pagination module :</p>
    <asp:PlaceHolder ID="Pagination" runat="server"></asp:PlaceHolder> 
</asp:Content>

Pagination.ascx.cs :

{
    public partial class Pagination : System.Web.UI.UserControl
    {
        public string urlNextPage { get; set; } = "defaultUrl";

        protected void Page_Load(object sender, EventArgs e)
        {
            link1.HRef = urlNextPage;
        }
    }
}

Pagination.ascx :

<%@ Control Language="C#" AutoEventWireup="true" Inherits="Back.UserControl.Pagination" CodeBehind="Pagination.ascx.cs"%>
<p>This is a test</p>
<a id="link1"  href="urlNextPage" runat="server" >Next page</a>

My probleme is that in the search.aspx, the href is not :

search.aspx?param1=test1&param2=test2 

but

/user_controls/search.aspx?param1=test1&param2=test2

How can i display the right url in the composant ?

1

There are 1 answers

0
Lucas Weibel On

So i founded a basic solution, in the Pagination.ascx.cs, I sended the url prefixed quite simply by "../" :

public partial class Pagination : System.Web.UI.UserControl
{
    public string urlNextPage { get; set; } = "defaultUrl";
    protected void Page_Load(object sender, EventArgs e)
    {
        link1.HRef = "../"+urlNextPage;
    }
}