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

Bases of creation of server elements of management. Events.

So that is necessary that our pager started to work really? Not too it is a lot of actually - it is necessary to describe only the delegate, to define{determine} event in an element of management and, if necessary, to describe the structure passing the data in obrabotchik of event. We also shall start with the announcement of the delegate.


The delegate as a matter of fact is the index on function in terms With ++. For the delegates determining events in server kontrolakh, additional restrictions are imposed - such delegate should accept 2 parameters, first of which should be such as object (in him the link to object is passed, sgenerirovavshij the given event), and the second - such as EventArgs (in this parameter the additional information connected to caused event) is passed. Class EventArgs - a base class for all classes passing the additional information, in itself he does not contain any properties for transfer of the information and is used in cases when event simply declares that it has taken place (for example event Click of a server element of management Button). In our case it is necessary to pass in event the additional data - new number{room} of page. Therefore for transfer of these data we shall define{determine} a class - the successor of class EventArgs.



public class PagerEventArgs: EventArgs

{

        public int SelectedPage;

        public PagerEventArgs (int SelectedPage)

        {

                this. SelectedPage = SelectedPage;

}

}


Then the announcement of the delegate for our event does not represent any problem:



public delegate void PagerEventHandler (Object sender, PagerEventArgs e);


And, accordingly, we shall add property of this type in our class.



public class Pager: WebControl

{

        public event PagerEventHandler Navigate;

        ...

}


Now it is necessary to address again to the theory. It is necessary for us, that our element of management in the first is skilful to generate postbeki, and in the second is skilful to receive and process the information postbeka. Thus also it is necessary, that at postbeke the information on number{room} of page was passed, cliques on which initiated it{him}. And such opportunity is, besides to realize her{it} in our element of management - business of 5 minutes:).


Remember, in previous clause{article} at otrisovke tegov <a> I hammered pustyshkoj teg href? There has come time to correct it and to add a call klentskoj the functions, generating postbek. For this purpose it is possible to use methods Page. GetPostBackEventReference or Page. GetPostBackClientHyperlink (job of these methods is practically identical, a difference only that GetPostBackClientHyperlink adds in the beginning of a returned line a line " javascript: "). The given methods accept 2 parameters - the index on the element of management generating postbek, and a line with the additional information. In our case values of these parameters will be the link this and number{room} of page of a link. Accordingly now the code deducing{removing} number{room} of page, will look so:



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

output. RenderBeginTag (HtmlTextWriterTag. A);

output. Write (pgIndex. ToString ());

output. RenderEndTag ();


postbeka too special jobs it is not necessary for reception - it is necessary to realize only interface IPostBackEventHandler in our control of management. I.e. to realize method RaisePostBackEvent of the given interface. This method accepts one parameter - a line containing the additional data which we defined{determined} by a call of method Page. GetPostBackClientHyperlink. Now we needed to obtain only these data (in fact in this parameter there is number{room} of the chosen page) and to call event.


But for the beginning we shall define{determine} the separate method checking presence attached obrabotchika of event and causing it{him} if obrabotchik is. This method usually has prefix On before a name of event:



protected virtual void OnNavigate (PagerEventArgs e)

{

        if (Navigate! = null)

                Navigate (this, e);

}


And only now we sell method RaisePostBackEvent



public void RaisePostBackEvent (string arg)

{

        int cmd = Int32. Parse (arg);

        PagerEventArgs e = new PagerEventArgs (cmd);

        CurrentPage = cmd;

        OnNavigate (e);

}


Everything, on it process of realization of functionality of our pager is completed. You can download a full code of an element of management under the link at the end of clause{article}.


In given clause{article} I have described only a small part of the questions connected to development of own elements of management and absolutely have said nothing about many other aspects of this problem. But to name them and to try show provisional ways of their decision I can:). So except for generation of the events based on postbeke of an element of management there are also questions of data processing at postbeke (interface IPostbackDataHandler), preservation / restoration of a status of elements of management at postbeke (methods LoadViewState and SaveViewState), problems and decisions of realization of a plenty of events in a class (class EventHandlerList) and sample elements of management. The separate big piece of creation of elements of management goes also creation of designers. But all this subjects for separate clauses{articles} which I was possible once also I shall be going to write:).





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