Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Lifecycle question

Lifecycle question

Scheduled Pinned Locked Moved ASP.NET
questiondatabasewpfwcfbusiness
5 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MBursill
    wrote on last edited by
    #1

    Probably a simple question. I have a form with a search button. The click event of the button calls a method for preforming a search. The search method returns a collection of business objects which I bind to a DataList. The binding only appears to work properly when done in the OnInit event. That's fine. The issue is in the order of the events. When the user clicks the search button the buttons click event isn't fired until after the init event. protected void btnSearch_Click(object sender, EventArgs e) { List customersList = Search(); // now what? It's not bound because the OnInit (where the binding code is) has already fired } I need to trigger a second post back to get the OnInit to fire again. Or do I? :confused: -Mike.

    U 1 Reply Last reply
    0
    • M MBursill

      Probably a simple question. I have a form with a search button. The click event of the button calls a method for preforming a search. The search method returns a collection of business objects which I bind to a DataList. The binding only appears to work properly when done in the OnInit event. That's fine. The issue is in the order of the events. When the user clicks the search button the buttons click event isn't fired until after the init event. protected void btnSearch_Click(object sender, EventArgs e) { List customersList = Search(); // now what? It's not bound because the OnInit (where the binding code is) has already fired } I need to trigger a second post back to get the OnInit to fire again. Or do I? :confused: -Mike.

      U Offline
      U Offline
      Uwe Keim
      wrote on last edited by
      #2

      Doing ASP.NET for several years, I never needed to handle OnInit(). Is there a reason you use it? Usually my code looks something like this:

      protected void Page_Load( object sender, EventArgs e )
      {
      if ( !IsPostBack )
      {
      List customersList = Search();
      ...
      }
      }

      -- • Zeta Producer Desktop CMS Intuitive, completely easy-to-use CMS for Windows. • Zeta Helpdesk Open Source ticket software for Windows and web. • Zeta Uploader Easily send large files by e-mail. Windows and web client. • Desargues Innovative, lean and neat calculator for Windows.

      M 1 Reply Last reply
      0
      • U Uwe Keim

        Doing ASP.NET for several years, I never needed to handle OnInit(). Is there a reason you use it? Usually my code looks something like this:

        protected void Page_Load( object sender, EventArgs e )
        {
        if ( !IsPostBack )
        {
        List customersList = Search();
        ...
        }
        }

        -- • Zeta Producer Desktop CMS Intuitive, completely easy-to-use CMS for Windows. • Zeta Helpdesk Open Source ticket software for Windows and web. • Zeta Uploader Easily send large files by e-mail. Windows and web client. • Desargues Innovative, lean and neat calculator for Windows.

        M Offline
        M Offline
        MBursill
        wrote on last edited by
        #3

        Reading the MSDN articles I was under the impression that dynamic content (in this case the template of my DataList has a custom control) needs to be created during the init event. But, if you say you can do it through the Page_Load I believe ya. However, so far that has not worked. This is what I have now tried:

        protected void Page\_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (SearchResults != null)
                {
        	        SearchResultsList.DataSource = SearchResults;
                SearchResultsList.DataBind();
            }
            }
        }
        
        protected void btnSearch\_Click(object sender, EventArgs e)
        {
            SearchResults = Search();
        }
        
        private List<Customer> SearchResults
        {
            get
            {
                return Session\["SearchResults"\] as List;
            }
        
            set
            {
                Session\["SearchResults"\] = value;
            }
        }
        

        When I hit search, nothing shows up. It doesn't appear as though the bind is ever happening. It's probably something obvious. Usually is the case. ;P -Mike.

        U 1 Reply Last reply
        0
        • M MBursill

          Reading the MSDN articles I was under the impression that dynamic content (in this case the template of my DataList has a custom control) needs to be created during the init event. But, if you say you can do it through the Page_Load I believe ya. However, so far that has not worked. This is what I have now tried:

          protected void Page\_Load(object sender, EventArgs e)
          {
              if (!IsPostBack)
              {
                  if (SearchResults != null)
                  {
          	        SearchResultsList.DataSource = SearchResults;
                  SearchResultsList.DataBind();
              }
              }
          }
          
          protected void btnSearch\_Click(object sender, EventArgs e)
          {
              SearchResults = Search();
          }
          
          private List<Customer> SearchResults
          {
              get
              {
                  return Session\["SearchResults"\] as List;
              }
          
              set
              {
                  Session\["SearchResults"\] = value;
              }
          }
          

          When I hit search, nothing shows up. It doesn't appear as though the bind is ever happening. It's probably something obvious. Usually is the case. ;P -Mike.

          U Offline
          U Offline
          Uwe Keim
          wrote on last edited by
          #4

          I guess you need to do something like this:

          protected void btnSearch_Click(object sender, EventArgs e)
          {
          SearchResults = Search();

          SearchResultsList.DataSource = SearchResults;
          SearchResultsList.DataBind();
          

          }

          -- • Zeta Producer Desktop CMS Intuitive, completely easy-to-use CMS for Windows. • Zeta Helpdesk Open Source ticket software for Windows and web. • Zeta Uploader Easily send large files by e-mail. Windows and web client. • Desargues Innovative, lean and neat calculator for Windows.

          M 1 Reply Last reply
          0
          • U Uwe Keim

            I guess you need to do something like this:

            protected void btnSearch_Click(object sender, EventArgs e)
            {
            SearchResults = Search();

            SearchResultsList.DataSource = SearchResults;
            SearchResultsList.DataBind();
            

            }

            -- • Zeta Producer Desktop CMS Intuitive, completely easy-to-use CMS for Windows. • Zeta Helpdesk Open Source ticket software for Windows and web. • Zeta Uploader Easily send large files by e-mail. Windows and web client. • Desargues Innovative, lean and neat calculator for Windows.

            M Offline
            M Offline
            MBursill
            wrote on last edited by
            #5

            That got it! I was actually already doing this when I first started, but nothing was showing up. Turns out the problem wasn't the order of where I set my DataSource but rather where I render my HTML in my custom control (the one in the template of the DataList). Thanks for your help. :-D -Mike.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups