Handling events using the ASP.NET button before OnPreInit

I have a data access layer, a business logic layer, and a presentation layer (i.e. the pages themselves).

I am handling the OnPreInit event and populating the collections needed for this page. All data comes from the SQL server database, and I do not use caching.

I am handling a button click event to capture values ​​from a form and insert a new object into the database. The problem is that by the time I handle the click event, the collections are already full, so the new item that was inserted into the database was not found.

What is an acceptable solution for this?

I could insert a new object directly into the collection and re-link the GridView, but the SQL query selects only the set of objects, and the new object may fall outside this set.

Thank!

+3
source share
5 answers

I usually do data binding in two places on my pages:

  • Inside Page_Load if! IsPostBack loads the initial state.

  • As one of the last lines in event handlers to show the result of adding / editing / deleting an entry.

, , - OnPreInit , , , , ( ).

+2

, . PreRender , .

+1

click. / . . , .

0
  • Extract the data to the Page.LoadComplete event and bind the data.
  • If for some reason they should retrieve them only on PreInit, and then retrieve them for the IsPostBack condition and bind them for the PostBack conditions, process them on LoadComplete
0
source

You can use this method to determine which control returned postback in PreInit: http://blogs.microsoft.co.il/blogs/gilf/archive/2010/03/01/discover-which-control-raised-a -postback.aspx

0
source

Source: https://habr.com/ru/post/1737593/


All Articles