ASP.NET Server control events   Part 7

ASP.NET Server control events Part 7



Oh welcome to presume technologies I am venket this is part 7 of asp.net video series in this session we'll learn about the events at an asp.net server control level before continuing with the session I strongly recommend to watch parts 4 and 6 of this video series in part 4 of this video series we have discussed that events can occur at 3 levels in an asp.net web application events can occur at the application level and examples of application level events include session start session and etc and application level events reside in the global dot aspx file events can also occur at the page level and examples of page level events include page load page pre-rendered page unload etc and finally the events can also occur at the control level examples of control level events include text change the event of a textbox control click event of a button control selected index change the event of a drop-down list control and you can find all these standard set of asp.net server control within the toolbox under so if you go to the web form and expand the toolbox under the standard tab you can find all the standard set of asp.net server controls you have another tab called validation tab and here you can find another set of validation controls and these controls expose validation events now all these controls in asp.net expose their own set of events and these events can be classified into three categories you know postback events what are these postback events these even submit the webpage immediately to the server for processing and examples for postback events include the click event of a button control now let's understand what we mean by postback event now look at this on this web form I'm going to the standard tab and dragging and dropping a button control onto this waveform now when I double click that button control it's going to generate the event handler and all I am doing here is writing a message to the response stream saying that button clicked all right so now let's go ahead and run this so obviously when we run this project the request for web form 1 is going to go back to the web server and then an instance of this platform gets created and sent back to the client now when I click this web form look at what's going to happen as soon as I click this the web form is immediately submitted to the web server for processing so the request goes to the server the server creates an instance of this web form process the page level events the button click event and then generates the HTML sends it back to the client and destroys that platform so once that HTML reaches the client you know you see this message button clicked why because in the click event we said you know write this message back to the response stream all right so that's the post back events which will immediately submit the web form to the server for processing now we have another category of events called cached events now what do we mean by cached events these events are saved in the page view state to be processed when a postback event occurs and examples of cached events include to exchange the event of a textbox control and along the same lines selected in the exchanged event of a drop-down list control let us actually see what we mean by cached events now if you remember we first dag dragged and drop the button control and we understood that button control expose a postback event now let's drag and drop a textbox control which again you can find in the standard tab of the toolbox so I have this textbox control let's double click that now textbox has an event called text changed so anytime you change the text in a text box text change the event will be fired okay so when I double click that I have I have this even handler automatically generated let's copy this and paste here and then instead of saying button clicked I'm going to say text changed all right so now let's go ahead and run this webform obviously now along with the button control we should also have textbox control now when we click the button control look at this that click event is fired the waveform is immediately submitted to the server for processing but whereas if we look at this I am typing some text into the text box and then I'm clicking away from the text box look at this did the page get submitted immediately to the server for processing now so which means this even now the text change the event is now cache in the view state of this page and when I click the button control what's going to happen the cached event will then be fired when the post bacc occurs so when I click the button look at look at what's going to happen so fast the text changed even meaning the cached event is fired and then the button click event is fired actually let's change this slightly let's put a break element here so that the output will be a little better all right let's close this browser window let's run the page once again actually let's put that for the text change the event as well all right let's run this now so now if I click the button the page will be immediately posted back to the server but whereas when I type some text into the text box look at this the text is changed in the text box but it didn't submit the page immediately to the server for processing but when I post the page back by clicking this button control that's when the cached event is fired okay so until you post the page back to the server for processing the cached events are cached in the view state of this page and then when you actually post the page back that's when the cached event and the post back events get executed together okay so that's the cached events so these events cached events are basically saved in the page view state to be processed when a postback event occurs to exchange the event of a text box control and selected index change the event of a drop-down list control are examples of cached events now you might be wondering okay so now I don't want this text changed event to wait until I click a button as soon as I change the text in the text box I want the page to be submitted to the web server for processing is that possible absolutely it's possible but you will have to convert that cashed event of the textbox control to a postback event so how do we do that it's very simple to do in asp.net all you will have to do is select the control on the webform and this control has got if you right click that and if you go into the properties window it has got this auto post bacc property which is false by default select that to true and if you look at the help here auto post back what is this doing this will automatically post back to the server after the text is modified so when we set this property to true you're telling okay anytime the text in this textbox changes submit the page immediately to the server for processing meaning convert that cached event into a postback event let's see if that's what is happening so let's run this page now and let's type some text into that so some text now for the event to be fired the textbox has to lose the focus and if it has to lose the focus you can press tab here the moment I press tab look at this the page got submitted back to the server you know for processing immediately so to convert a cached event into perspective and all you will have to do is to change the auto post back property to true the same is applicable for a drop-down list as well alright so now we have another set of events called validation events so what are these validation events you know basically we have a set of validation controls within the tool box you can find them under the validation tab and these controls are used to validate the user input before the form is submitted back to the server for processing we will be talking about validation controls in detail in a later session the idea of this video session is basically to understand the different types of events that these server controls expose and how they interact along with the page-level events in a later video session we will talk about all the events the standard asp.net server controls expose and how to use them along along the same lines we'll also see how to use this validation control okay but for now just you know let's take an example of required field value data control let's rearrange this a little bit let's take the button control and put it after the textbook so all I have here is the required field validator a textbox in a button control now what I'm going to do is I'm going to right click the required field validator control go to its properties and then there is one property called control to validate now these validation controls are used to validate you know the controls on the webform so I want to you know make sure that somebody enters something into this webform before they click the button in order to submit the platform to the server for processing so if I want to enter something is there in the textbox I can make use of this required field valid data now you'll have to tell this required field validator which control it has to validate and you do that by using this property called control to validate now which control do I want to validate textbox one all I have to do is select that property that's it you can change this error message if you want to you know there's another property called error message but we will not change that now all right so I think I have hit f5 by mistake all right so now let's go ahead and run this and then when I click the submit button without entering any text I had I didn't enter anything into the textbox I click the button look at this required a field validator is fired the page did get submitted to the server if it if it got submitted then obviously we would have caught that you know button click to message but we didn't get this which means this waveform is now not submitted to the web server for processing okay that's because we have this validation event happening on the client even before the webform is submitted to the server for processing so validation events they happen on the client actually there is a Java Script you know which is emitted by this control which runs on the client browser and that that basically ensures that there is something the user has typed into this text box before the user can actually submit this form to the server for processing and that's what is validating on the client so validation events happen on the client so these events occur on the client before the page is posted back to the server all validation controls use these type of events so until now we have understood that asp.net server controls expose you know three types of events postback events cached events and validation events now in the previous session we have seen even set the web form level and if you remember these are the events at the web forum level pre initialization init init complete and we have spoken about them in a great detail in the previous session and if you remember control events actually happen after the page load event okay what are the examples of control events we have just seen a few of them click event exchanged event okay so those events happen after the page load event and before load complete okay so let's see them actually in action so if you look at this so I I have this web browser the client ok so I have if you look at on the web form at the minute I only have button control text box and a validation control and if you look at the code behind page all I have is the click event of the button control text change the event of the textbox control now I'm going to copy paste these lines and this is pretty simple again I've just written pre-written this just to save some time in typing and if you look at this this is pretty simple code all we are doing is having an event handler for all the page level events and if you remember these are the page level events we have spoken about them in the previous session so in pre Anette page pre Anette what we are doing all we are doing is printing this message similarly page initialization printing that message and we have all these page level events and then the control leave in stem cells button click 'next Xchange so now when I run this platform with all these events in place let's close that control f5 now the web form should load and if you don't type anything into the text box and try to submit the page look at this first of all you know when we requested the web form the web form instance is created all the page level events are processed look at this all the page level events page pre init init init complete etc but do you find the button click event or the text change the event you don't because why this is the initial get request you didn't submit a page so during the initial get request only the page level even skipped process and once the HTML is rendered back to the client now user can type whatever he wants into the textbox make any selections in the drop-down list etc and then he click the button to submit the page back to the server for processing but now let's say we don't enter anything into this text box and try to submit this page obviously there is a validation control which is running on the client the validation events happen on the client even before the waveform is submitted to the server and this will ensure that you have entered something into the textbox before actually submitting it okay so if I type some text into the textbox and then when I submit this page okay we have this text you know if you remember we turned on the auto post back property of the textbox to true which converted it into you know post back here and let's flip that back to cached event so how do we do that select the text box set the auto post back property to false let's close the webform let's run this once again and now let's type some text into the textbox and then when I click away it doesn't post the page back immediately because the event is cached now and when I click the button look at what's going to happen the page gets posted back as usual page pre init init init complete preload and then look at this text changed and button click you don't see the load even there okay let us see if we have the even handle of a page load or not it should be there if it's there then it should be executed so we have page preload but we don't have an event handler for load even then that's the reason why we don't see it there so let's have an event for page load and let's call this page load so let's close this run that again enter some text click the button look at this these are all the page level events until page load and after that the cached event is fired and then the postback event and then the rest of the page level events page load complete pre-render and pre-render complete so if you look at this graph diagram that's what you know if you have civil control events and page level events together on a webform and if it's submitted to the server for processing how do they interact you know the page level events happen as usual until the load event and then any control level events or process if you have cached and post bacc events first the cached events are processed and then the post bacc events are processed and finally the rest of the page level events get processed and the response is sent back to the server and page unload happens finally on this slide you can find resources for asp.net c-sharp and sequels of interview questions that's it for today thank you for listening have a great day

Author:

38 thoughts on “ASP.NET Server control events Part 7”

  • Once again: Viewstate is never changed on the client. The data to be handled for cached events are not sent in viewstate it's sent as post back data.

  • Nishikant Chelluri says:

    hi sir this is Nishikant …

    i have created a asp.net web application

    in that iam getting the server error…
    here i have used a Rowdatabound and rowCommand properties of Gridview
    in Rowdatabound i have created and added a button in rows of ItemLists Column
    Same Button name with Same command argument used.
    when iam using the button in gridview Datarow it is firing..
    but the second time after doing filteration > filtered in Gridview>Same Button(with same Command argument)->is not firing ->the error is coming …..

    Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation

    Sir How to solve the above error….

  • Hi venkat ,

    i am New to ASP .net . i convert cached event in to post bock now button should also fire post back event and text box also .but text box is alone firing the event , is there any priority..plz let me know

    Best regards,
    Mohit

  • Hi Venket, Thanks for quick and smart teaching, I have small question. How to insert the page_preInt, page_int……… etc? Do we need manual type?

  • why my project run load message
    ————————————————————————————————————————–
    Server Error in '/' Application.
    —————————————————————————————————————————-
    Configuration Error

    —————————————————————————————————————————–

    Description: An error occurred during the processing
    of a configuration file required to service this request. Please review
    the specific error details below and modify your configuration file
    appropriately.

    ————————————————————————————————————–

    Parser Error Message: Could not load file or
    assembly 'CrystalDecisions.ReportAppServer.ClientDoc,
    Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304'
    or one of its dependencies. The system cannot find the file specified.

    Source Error:

    ————————————————————————————————————–

    Line 36: <add assembly="CrystalDecisions.Shared, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
    Line 37: <add assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
    Line 38: <add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
    Line 39: <add assembly="CrystalDecisions.Enterprise.Framework, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
    Line 40: <add assembly="CrystalDecisions.Enterprise.InfoStore, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />

  • All the videos are worth watching if some one wants to learn Dot Net and Page Life cycle is explained in the best possible way.
    Thank you So much For The Video Presentation On all the Topic Related to Dot Net.

  • Alex Martinez says:

    I got a UnobtrusiveValidationMode error,  so I copied this for resolve this issue to my webconfig file between, By the way thanks a lot for this tutorial, is excelent.
    <configuration>
    <appSettings>
        <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
      </appSettings>
    </configuration>

  • Kruthika Shastry says:

    Hello Venkat Sir,

    I am a beginner in asp .net and your videos are helping a lot Sir! I have a doubt regarding Cached events. When I change the text of a text box and press enter I can see the response "Text changed". Can you please explain what exactly happens when I click enter? Please tell me if you need more details.

    I do hope you reply Sir. It is very important for me. I am searching for a new job in asp .net field

    Regards
    Kruthika

  • I am very grateful to you sir for making me understand this life cycle, it is not clear anywhere. It could be better if you even tell us the other life cycle events.

  • Thank you very much for taking time to give feedback. In the description of this video, I have included the link for ASP .NET, C#, and SQL Server playlists. All the videos are arranged in logical sequence in these playlists, which could be useful to you. Please share the link with your friends who you think would also benefit from them. If you like these videos, please click on the THUMBS UP button below the video. For email alerts, when new videos are uploaded, you may subscribe to my channel.

  • i just can t believe how you explain everything, always when you do something i wonder what if i do it in another way and then 2 minutes later you explain the other way. watching your tutorials day and night.

  • very helpful ….may i know where you are from? ur english is excellent but u kinda have a indian accent.. 🙂 am i right

  • Numan Farooqui says:

    Hello sir ,your videos are helping a lot,
    Sir when m changing the autopostback property of textbox and running the application as soon as i write some text in textbox n click the button only"Text Changed" is showing on my page n "Button Clicked" is not appearing
    Can u plz explain y it's so???
    thanks a lot

  • thank u very much kudvenkat 🙂 our prayers are with you .. you are doing the amazing job …these tutorials are really helpful for beginners .. i m really thankful to u …GOD bless u

  • Thanks a lot…. very helpful tutorial for us beginners in ASP.NET… I will try to finish all of ur videos… 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *