Paging long articles in ASP.NET using C#
Paging long articles in ASP.NET using C#
Long articles are better broken into bite-sized chunks over several pages. With static HTML, this is easily achieved by dividing the article into logical separations and creating separate .htm files for each. Here's how to do it using C# for an article that gets posted to a database.
The Regular Expression Split() method returns a one-dimensional zero-based array containing a number of substrings, so it is perfect for this job. What I want to do is take an article (which is a string) and divide it into substrings. In order to do this, I need a delimiter, and I use <!--pagebreak-->. As I enter the article into the database, I place <!--pagebreak--> at the points I want to break the article.
Then, having extracted the article from the database, I pass it to the following static method which I have in a utility class:
public static string PageArticle(string Article)
{
string Output;
string ThisPage = HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"];
string PageNo;
PageNo = HttpContext.Current.Request.QueryString["Page"];
if (Article.IndexOf("<!--pagebreak-->") != -1)
{
string[] Pages = 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];
Output += "<p>Go to Page ";
while (Counter <= TotalPages)
{
if (Counter == PageNumber)
{
Output += Counter.ToString() + " ";
}
else
{
Output += "<a href="\" mce_href="\""" + ThisPage + "?Page=" + Counter.ToString();
Output += "\">" + Counter.ToString() + "</a> ";
}
Counter++;
}
Output += "</p>";
}
else
{
Output = Article;
}
re
Ïà¹ØÎĵµ£º
1.//µ¯³ö¶Ô»°¿ò.µã»÷תÏòÖ¸¶¨Ò³Ãæ
Response.Write(" <script>window.alert('¸Ã»áԱûÓÐÌá½»ÉêÇë,ÇëÖØÐÂÌá½»£¡')
</script>");
Response.Write(" <script>window.location
='http://www.51aspx.com/bizpulic/upmeb.aspx' </script>");
2.//µ¯³ö¶Ô»°¿ò
Response.Write(" <script lang ......
ÔÚ²»Ö§³ÖCookiesµÄÒÆ¶¯É豸ģÄâÆ÷ÖÐÎÞ·¨Õý³£½øÐÐ±íµ¥ÑéÖ¤,ÁªÏëµ½×òÌìʹÓÃweb.configÉèÖÃcookielessÊôÐÔʱ»áÔÚ·ÃÎÊʱ»á³öÏÖ"Cannot use a leading .. to exit above the top directory"µÄÒì³£,×ÔÈ»¶øÈ»µÄÎÒ¾ÍÏëµ½ÁËǰһ¶Îʱ¼äÀ§ÈÅÎҺܾõÄÒ»¸öÕ¾µãÒì³£ÎÞ·¨Ê¹ÓÃǰµ¼ .. ÔÚ¶¥¼¶Ä¿Â¼ÉÏÍ˳ö(Cannot use a leading .. to exit abo ......
dz̸ASP.NETµÄÄÚ²¿»úÖÆ(Ò»)
dz̸ASP.NETµÄÄÚ²¿»úÖÆ(¶þ)
dz̸ASP.NETµÄÄÚ²¿»úÖÆ(Èý)
dz̸ASP.NETµÄÄÚ²¿»úÖÆ(ËÄ)
dz̸ASP.NETµÄÄÚ²¿»úÖÆ(Îå)
dz̸ASP.NETµÄÄÚ²¿»úÖÆ(Áù)
dz̸ASP.NETµÄÄÚ²¿»úÖÆ(Æß)
dz̸ASP.NETµÄÄÚ²¿»úÖÆ(°Ë) ......
ÔÚGlobal.asax
ÐèÒª»Ø¹ËµÄ֪ʶµãÊÇ Ïß³Ì ºÍ Îı¾ÎļþµÄ¶Áд¡£
<%@ Application Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Threading" %>
<script runat="server">
string logpath;
Thread thread;
......
ÈÏʶASP.NETÅäÖÃÎļþWeb.config
×÷ÕߣºSabine¡¡À´Ô´£ºÈüµÏÂÛ̳
¡¡¡¡Ò»¡¢ÈÏʶWeb.configÎļþ
Web.configÎļþÊÇÒ»¸öXMLÎı¾Îļþ£¬ËüÓÃÀ´´¢´æ ASP.NET Web Ó¦ÓóÌÐòµÄÅäÖÃÐÅÏ¢£¨Èç×î³£ÓõÄÉèÖÃASP.NET Web Ó¦ÓóÌÐòµÄÉí·ÝÑéÖ¤·½Ê½£©£¬Ëü¿ÉÒÔ³öÏÖÔÚÓ¦ÓóÌÐòµÄÿһ¸öĿ¼ÖС£µ±Äãͨ¹ýVB.NETн¨Ò»¸öWebÓ¦ÓóÌÐòºó£¬Ä¬ÈÏÇé¿ ......