Page 1 of 1

Request.QueryString help needed

Posted: Tue Sep 29, 2009 1:18 pm
by William_firefold
I have a conlib on the frontpage which loads products 200 at a time. It uses most of the code from the "featured products" conlib with minor adjustments:

Code: Select all

    protected void Page_Load(object sender, EventArgs e)
    {
        _GlobalDisablePurchase = Token.Instance.Store.Settings.ProductPurchasingDisabled;
        if (!string.IsNullOrEmpty(this.Caption)) CaptionLabel.Text = this.Caption;
        ProductList.RepeatColumns = this.Columns;
	pager=AlwaysConvert.ToInt(Request.QueryString["p"]);////////////////////
        ProductList.DataSource = ProductDataSource.LoadForStore(200,200* pager);//////////////////////
        ProductList.DataBind();
    }
I am having trouble figuring out how to make a link at the bottom of the page with http://_________/?p+1 (ie the next page) in the href field.

Code: Select all

<asp:HyperLink ID="nextlink" runat="server" NavigateUrl='<%# getnextpageurl()%>'>Next</asp:HyperLink>
wasnt working for me for some reason.
Anyone know how to do this? Maybe Im just not formatting my hyperlink properly. Any advice appreciated.

Re: Request.QueryString help needed

Posted: Tue Sep 29, 2009 2:13 pm
by AbleMods
Your hyperlink markup looks correct. Where's the code-behind for the getnextpageurl() function?

Re: Request.QueryString help needed

Posted: Tue Sep 29, 2009 4:11 pm
by afm
Should it be <%= getnextpageurl()%> instead of <%# getnextpageurl()%>?

They both might work (or not work) if something is calling DataBind on the page, otherwise the %# syntax will never be resolved.

Re: Request.QueryString help needed

Posted: Wed Sep 30, 2009 5:51 am
by William_firefold
This is the function I am trying to create:

Code: Select all


protected string getnextpageurl()
    {
	int pager=AlwaysConvert.ToInt(Request.QueryString["p"]);
        return "http://new.website.com/?p="+(pager+1).ToString();
    }
When i used <%= getnextpageurl()%>
It set the link address to this : http://new.website.com/ConLib/custom/<%= getnextpageurl() %>
When I use <%# getnextpageurl()%> the link has no address at all.

Re: Request.QueryString help needed

Posted: Wed Sep 30, 2009 6:35 am
by AbleMods
Hmmm I'm not sure the server-side hyperlink control supports substitution on the NavigateUrl.

Try leaving the NavigateUrl blank in the HTML and assigning it the correct value during Page_Load()

Code: Select all

.
.
.
int pager=AlwaysConvert.ToInt(Request.QueryString["p"]);
if (pager > 0)
   nextlink.NavigateUrl = "http://new.website.com/?p="+(pager+1).ToString();
else
   nextlink.Visible = false;
.
.
.

Re: Request.QueryString help needed

Posted: Wed Sep 30, 2009 6:55 am
by William_firefold
That fixed it.
Thanks Joe.

Re: Request.QueryString help needed

Posted: Wed Sep 30, 2009 7:59 am
by AbleMods
Groovy