Home
Links
Home Page
HTML_AJAX In operation
The guidebook on an exchange of links
Bases of creation of server elements of management. Events
Postback and Query String - to combine incompatible
Kategorial`noe ordering of results of search
We change URL'? hurriedly
XML+MSSQL+ASP.NET. A part 1.
As work Web services ASP.NET
New in ASP.NET 2. Structures of users
Transformation of a target stream of the XML-given at a conclusion in a browser means ASP.NET and XS
Expectation of performance of long process in ASP.NET
Difference between HttpModule and HttpHandler
New in asp.net 2 - subjects and skiny.
Review GridView
What is GridView
Role of a content in promotion of a site
Review DetailsView
Job with databases
AutoPostBack Binding to the data. Collections. Check of correctness of the entered data


Postback and Query String - to combine incompatible

I think any of the programmers writing a web of the application with the help a web of forms, server elements of management and sobytijno focused programming, will agree with the statement, that the given technology has very strongly facilitated work of programmers. But any event / ??®?????/»?«?????? has both positive, and the negative parties{sides}. And one of such negative parties{sides} in our case is extremely problemtichnoe creation of system of navigation which would be simultaneously and convenient for programming (i.e. would be based on server elements of management) and convenient for search robots (would consist of a set of the banal links containing well understandable any to browser tegi <a>). I have reflected on it after have found out sharp discrepancy of real quantity{amount} of pages on mania and that quantity{amount} of pages which is in bases of search engines. And all of that lists of messages in forums at me were deduced{removed} with the help of an element of management DataGrid with the switched on paginal conclusion. Sootvestvenno there has come time a little to correct this omission.


In last clause{article} I have given an example a spelling and a full initial code of a server element of management Pager which, I hope, pleased our readers. Now there has come time a little to expand it{him} that on pages could pass not only users, but also search robots. And for this purpose it is necessary to make so that at links in which generjatsja buttons of an element of management, there was not only skripotovaja a processing of event of pressing the link, but also the ordinariest well understood by all kinds of browsers an element href, containing the ordinariest link. Thus, estesstvenno, postarajas` completely to save external functionality of an element of management.


For the beginning we shall recollect what in the image in last clause{article} generated a code for initiation client postbeka - using method Page. GetPostBackClientHyperlink. And I then have still noted, that also it is possible to apply method Page. GetPostBackEventReference for this purpose - all difference between results of a call of these 2 methods consists in a line ” javascript: “, which is present at the beginning of a returned line of result of a call of the first method and absent for the second method. Accordingly the call of method Page. GetPostBackClientHyperlink is the most convenient for applying at installation of attribute href links, and Page. GetPostBackEventReference - at installation of client attribute onclick. Sootv. A first step which should be made for completion of an element of management Pager updating of the line inserting JavaScript in teg <a> - instead of



output. AddAttribute (HtmlTextWriterAttribute. Href, Page. GetPostBackClientHyperlink (this, (pgIndex - 1) .ToString ()));

output. RenderBeginTag (HtmlTextWriterTag. A);

output. Write (pgIndex. ToString ());

output. RenderEndTag ();


We shall write now



output. AddAttribute (HtmlTextWriterAttribute. Onclick, Page. GetPostBackEventReference (this, (pgIndex - 1) .ToString ()) + "; return false; ");

output. RenderBeginTag (HtmlTextWriterTag. A);

output. Write (pgIndex. ToString ());

output. RenderEndTag ();


But it yet all changes in links to pages - to us is necessary for adding also in these links attributes href that any browser which is at all not supporting JS, could pass on pages. I have hammered in the given procedure rigidly in a code, but nothing prevents you to make her{it} more beautifully. So for links I used parameter PageNum which defines{determines} number{room} of page.


First of all for generation of correct values of attributes href links it is necessary for us to receive takushij url pages, then to make with it{him} some manipulations (probably in urle parameter PageNum already contains - it{he} needs to be cut out therefrom) and the turned out line we can use for creation of the links necessary to us. Accordingly in the first lines of method Render we write the following code:



string pageUrl = Context. Request. RawUrl;

pageUrl = System. Text. RegularExpressions. Regex. Replace (pageUrl, " *PageNum = (d +) ", " ");

pageUrl = System. Text. RegularExpressions. Regex. Replace (pageUrl, "? PageNum = (d +) ", " ");

if (pageUrl. IndexOf ("?")>-1)

      pageUrl + = " *PageNum = ";

else

      pageUrl + = "? PageNum = ";


I think specially to assort his{its} sense no - he is clear enough and without it:). Now we only needed to use received pageUrl approximately so:



output. AddAttribute (HtmlTextWriterAttribute. Href, pageUrl + (pgIndex - 1) .ToString ());


Everything, the section of generation html a code completely is finished. Now if the user with a browser supporting JS, will press a link of page - will work a client script from the unit onclick. Well and for the search robot (or a browser with otkljucheniiym a script) always there is an opportunity to go directly under the link:)


There was a business for small - to make so that our links successfully worked also event of transition to new page was generated and in case of transition under the link with parameter, and not just at postbeke. And the most successful for this purpose a place it, strangely enough, the beginning of method RenderContents. In fact we need to generate event Navigate not only at presence of parameter in an address bar, but also (that is much more important) at postbeke, generated by a pager. Except for that it is not necessary to forget and about such thing, as dynamic addition of the data on page at which the normal order of presence of elements of management on page and working off of events Init and Load is broken that can lead to to unpredictable job quite like predicted kontrolov. Therefore in end we shall add in the beginning of method RenderContents of a line, whether which check postbek given rekyest and whether there is in an address bar parameter PageNum and in case of performance of these conditions establish property CurrentPage of an element of management and cause method RaisePostBackEvent:



if (! Page. IsPostBack ** Context. Request. QueryString ["PageNum"]! = null)

{

            CurrentPage = Int32. Parse (Context. Request. QueryString ["PageNum"]);

            RaisePostBackEvent (CurrentPage. ToString ());

}


On it process of adaptation of an element of management Pager for job with the data in an address bar can be counted completed. Now on your pages with the data the users using any browser, including kraulery search engines can wander.


I express the gratitude and gratitude to Igor T. aka Legioner for idea:)







© Web Development Company Conkurent, LLC 2008-2009. All rights reserved.