खोज…


जीवन चक्र की घटनाएँ

निम्नलिखित पृष्ठ जीवन चक्र की घटनाएं हैं:

PreInit - PreInit पृष्ठ जीवन चक्र में पहली घटना है। यह IsPostBack संपत्ति की जाँच करता है और यह निर्धारित करता है कि पृष्ठ पोस्टबैक है या नहीं। यह थीम और मास्टर पृष्ठ सेट करता है, गतिशील नियंत्रण बनाता है, और प्रोफाइल गुण मान प्राप्त करता है और सेट करता है। इस घटना को OnPreInit विधि को ओवरराइड करके या Page_PreInit हैंडलर बनाकर नियंत्रित किया जा सकता है।

Init - Init इवेंट कंट्रोल प्रॉपर्टी को इनिशियलाइज़ करता है और कंट्रोल ट्री बनाया जाता है। इस घटना को OnInit विधि को ओवरराइड करके या Page_Init हैंडलर बनाकर नियंत्रित किया जा सकता है।

InitComplete - InitComplete ईवेंट दृश्य स्थिति की ट्रैकिंग की अनुमति देता है। सभी नियंत्रण दृश्य-राज्य ट्रैकिंग को चालू करते हैं।

LoadViewState - LoadViewState ईवेंट नियंत्रण में स्थिति जानकारी लोड करने की अनुमति देता है।

LoadPostData - इस चरण के दौरान, टैग के साथ सभी इनपुट फ़ील्ड की सामग्री को परिभाषित किया गया है।

PreLoad - PreLoad पोस्ट बैक डेटा के नियंत्रण में लोड होने से पहले होता है। इस घटना को OnPreLoad विधि को ओवरराइड करके या Page_PreLoad हैंडलर बनाकर नियंत्रित किया जा सकता है।

लोड - लोड घटना को पहले पृष्ठ के लिए और फिर सभी बच्चे नियंत्रण के लिए पुनरावर्ती रूप से उठाया जाता है। नियंत्रण पेड़ में नियंत्रण बनाया जाता है। इस घटना को OnLoad विधि को ओवरराइड करके या Page_Load हैंडलर बनाकर नियंत्रित किया जा सकता है।

LoadComplete - लोडिंग प्रक्रिया पूरी हो गई है, कंट्रोल इवेंट हैंडलर चलाए जाते हैं, और पृष्ठ सत्यापन होता है। इस घटना को OnLoadComplete विधि को ओवरराइड करके या Page_LoadComplete हैंडलर बनाकर नियंत्रित किया जा सकता है

PreRender - PreRender इवेंट आउटपुट होने से ठीक पहले होता है। इस घटना को संभालने से, आउटपुट दिए जाने से पहले पृष्ठ और नियंत्रण कोई भी अपडेट कर सकते हैं।

PreRenderComplete - जैसा कि PreRender ईवेंट को सभी चाइल्ड कंट्रोल के लिए पुनरावर्ती रूप से निकाल दिया जाता है, यह इवेंट प्री-रेंडरिंग चरण के पूरा होने को सुनिश्चित करता है।

SaveStateComplete - पृष्ठ पर नियंत्रण की स्थिति सहेजी जाती है। वैयक्तिकरण, नियंत्रण स्थिति और दृश्य स्थिति जानकारी सहेज ली जाती है। HTML मार्कअप उत्पन्न होता है। इस चरण को रेंडर विधि को ओवरराइड करके या पेज_रेंडर हैंडलर बनाकर नियंत्रित किया जा सकता है।

UnLoad - UnLoad चरण पृष्ठ जीवन चक्र का अंतिम चरण है। यह पृष्ठ के लिए पुनरावर्ती और अंत में सभी नियंत्रणों के लिए UnLoad घटना को बढ़ाता है। अंतिम सफाई की जाती है और सभी संसाधनों और संदर्भों, जैसे डेटाबेस कनेक्शन, को मुक्त कर दिया जाता है। इस घटना को OnUnLoad विधि को ओवरराइड करके या Page_UnLoad हैंडलर बनाकर नियंत्रित किया जा सकता है।

कोड उदाहरण

using System;

namespace myProject
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        public string PageSteps = string.Empty;

        //Raised after the start stage is complete and before the initialization stage begins.
        protected void Page_PreInit(object sender, EventArgs e)
        {
            PageSteps += "1 - Page_PreInit<br>";

            //Access to page Controls not available in this step
            //Label1.Text = "Step 1";
        }

        //Raised after all controls have been initialized and any skin settings have been applied.
        //The Init event of individual controls occurs before the Init event of the page.
        protected void Page_Init(object sender, EventArgs e)
        {
            PageSteps += "2 - Page_Init<br>";

            Label1.Text = "Step 2";
        }

        //Raised at the end of the page's initialization stage.
        //Only one operation takes place between the Init and InitComplete events: tracking of view state changes is turned on.
        //View state tracking enables controls to persist any values that are programmatically added to the ViewState collection.
        //Until view state tracking is turned on, any values added to view state are lost across postbacks.
        //Controls typically turn on view state tracking immediately after they raise their Init event.
        protected void Page_InitComplete(object sender, EventArgs e)
        {
            PageSteps += "3 - Page_InitComplete<br>";

            Label1.Text = "Step 3";
        }

        //Raised after the page loads view state for itself and all controls, and after it processes postback data that is included with the Request instance.
        protected override void OnPreLoad(EventArgs e)
        {
            PageSteps += "4 - OnPreLoad<br>";

            Label1.Text = "Step 4";
        }

        //The Page object calls the OnLoad method on the Page object, and then recursively does the same for each child control until the page and all controls are loaded.
        //The Load event of individual controls occurs after the Load event of the page.
        protected void Page_Load(object sender, EventArgs e)
        {
            PageSteps += "5 - Page_Load<br>";

            Label1.Text = "Step 5";
        }

        //Use these events to handle specific control events, such as a Button control's Click event or a TextBox control's TextChanged event.
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //Step only visible on PostBack
            PageSteps += "6 - btnSubmit_Click<br>";

            Label1.Text = "Step 6";
        }

        //Raised at the end of the event-handling stage.
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            PageSteps += "7 - Page_LoadComplete<br>";

            Label1.Text = "Step 7";
        }

        //Raised after the Page object has created all controls that are required in order to render the page, including child controls of composite controls.
        //(To do this, the Page object calls EnsureChildControls for each control and for the page.)
        protected override void OnPreRender(EventArgs e)
        {
            PageSteps += "8 - OnPreRender<br>";

            Label1.Text = "Step 8";
        }

        //Raised after each data bound control whose DataSourceID property is set calls its DataBind method.
        protected override void OnPreRenderComplete(EventArgs e)
        {
            PageSteps += "9 - OnPreRenderComplete<br>";

            Label1.Text = "Step 9";
        }


        //Raised after view state and control state have been saved for the page and for all controls.
        //Any changes to the page or controls at this point affect rendering, but the changes will not be retrieved on the next postback.
        protected override void OnSaveStateComplete(EventArgs e)
        {
            PageSteps += "10 - OnSaveStateComplete<br><hr><br>";

            Label1.Text = "Step 10";
        }

        // Render
        //This is not an event; instead, at this stage of processing, the Page object calls this method on each control.
        //All ASP.NET Web server controls have a Render method that writes out the control's markup to send to the browser.

        //Raised for each control and then for the page.
        //Controls use this event to do final cleanup for specific controls, such as closing control-specific database connections
        protected void Page_UnLoad(object sender, EventArgs e)
        {
            //This last PageSteps addition will not be visible on the page
            PageSteps += "11 - Page_UnLoad<br>";

            //Access to page Controls not available in this step
            //Label1.Text = "Step 11";      
        }
    }
}

जीवन चक्र में चरणों की कल्पना करने के लिए .aspx पृष्ठ पर निम्न कोड जोड़ें।

<b>Page Life Cycle Visualization:</b>
<br />
<%= PageSteps %>

यहाँ छवि विवरण दर्ज करें

अधिक जानकारी



Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow