M
Mike
ASP.NET 2.0
I have some code working in a code-behind that I want to move to a utility
class. In the code behind, I can reference the querystring and get the
Page value easily. However, when I try to reconstruct the method (below) in
a separate class, my attempt to reference the querystring of the page that
calls the PageArticle method is throwing the error in the subject of the
post.
public sealed class Utils
{
private Utils() {}
public static string PageArticle(string Article)
{
string Output;
string PageNo = System.Web.UI.Page.Request.QueryString["Page"];
//Throws error
if (Article.IndexOf("<!--pagebreak-->") != -1)
{
string[] Pages =
System.Text.RegularExpressions.Regex.Split(Article, "<!--pagebreak-->");
int TotalPages = Pages.GetUpperBound(0) + 1;
int Counter = 1;
int PageNumber = 1;
if (PageNo != null)
{
PageNumber = System.Convert.ToInt32(PageNo);
}
Output = Pages[PageNumber - 1] + "<br />";
Output += "Go to Page ";
while (Counter <= TotalPages)
{
if (Counter == PageNumber)
{
Output += Counter.ToString() + " ";
}
else
{
Output += "<a href=\"Article.aspx?Page=" +
Counter.ToString() + "\">" + Counter.ToString() + "</a> ";
}
Counter++;
}
}
else
{
Output = Article;
}
return Output;
}
}
Can anyone point out what I've done wrong?
Thanks
I have some code working in a code-behind that I want to move to a utility
class. In the code behind, I can reference the querystring and get the
Page value easily. However, when I try to reconstruct the method (below) in
a separate class, my attempt to reference the querystring of the page that
calls the PageArticle method is throwing the error in the subject of the
post.
public sealed class Utils
{
private Utils() {}
public static string PageArticle(string Article)
{
string Output;
string PageNo = System.Web.UI.Page.Request.QueryString["Page"];
//Throws error
if (Article.IndexOf("<!--pagebreak-->") != -1)
{
string[] Pages =
System.Text.RegularExpressions.Regex.Split(Article, "<!--pagebreak-->");
int TotalPages = Pages.GetUpperBound(0) + 1;
int Counter = 1;
int PageNumber = 1;
if (PageNo != null)
{
PageNumber = System.Convert.ToInt32(PageNo);
}
Output = Pages[PageNumber - 1] + "<br />";
Output += "Go to Page ";
while (Counter <= TotalPages)
{
if (Counter == PageNumber)
{
Output += Counter.ToString() + " ";
}
else
{
Output += "<a href=\"Article.aspx?Page=" +
Counter.ToString() + "\">" + Counter.ToString() + "</a> ";
}
Counter++;
}
}
else
{
Output = Article;
}
return Output;
}
}
Can anyone point out what I've done wrong?
Thanks