3 Replies - 1043 Views - Last Post: 29 April 2011 - 01:15 PM Rate Topic: -----

#1 krum110487  Icon User is offline

  • D.I.C Regular

Reputation: 39
  • View blog
  • Posts: 291
  • Joined: 07-February 09

Persisting Dynamically Created Content

Posted 29 April 2011 - 12:19 PM

If I add a control to a page dynamically (lets say validation) and I leave the page and come back, does it have to run the code AGAIN to add the validation? or does ASP automatically cache it, I plan for it to be the same every time, but I want to add it via code-behind to clean up the ASPx code.

Currently I am adding all of the validation on a page OnInit Function, it works fine, but I fear it will be pretty slow over time, or possible a page with a lot of validation.

is there a way to add it once to a page on application load and it not have to be dynamically generated every time you hit the page? or does it work just as if I added it to the page myself? (speed wise)

if not I will implement my own caching system.

Thanks!

(PS I have googled this, but I don't really know what I am looking for)

This post has been edited by krum110487: 29 April 2011 - 12:23 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Persisting Dynamically Created Content

#2 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Persisting Dynamically Created Content

Posted 29 April 2011 - 12:30 PM

In my opinion , i don't think this can be done to be honest , after each postback the page resets itself to its original state.

But im really not sure about this.



Quote

Currently I am adding all of the validation on a page OnInit Function, it works fine, but I fear it will be pretty slow over time, or possible a page with a lot of validation.


Recreating controls is fast so you don't have to worry about speed

What you can do is create small method's like


void CreateTextBox(Panel pnl)
{
   TextBox text = new TextBox();

   pnl.Controls.Add(text);

}


Then simply call this method

CreateTextBox(PnlID);


Every time you need to create the control.

I could be wrong maybe there is a way.. But i doubt it.

This post has been edited by marinus: 29 April 2011 - 12:35 PM

Was This Post Helpful? 1
  • +
  • -

#3 krum110487  Icon User is offline

  • D.I.C Regular

Reputation: 39
  • View blog
  • Posts: 291
  • Joined: 07-February 09

Re: Persisting Dynamically Created Content

Posted 29 April 2011 - 01:02 PM

View Postmarinus, on 29 April 2011 - 12:30 PM, said:

In my opinion , i don't think this can be done to be honest , after each postback the page resets itself to its original state.

But im really not sure about this.



Quote

Currently I am adding all of the validation on a page OnInit Function, it works fine, but I fear it will be pretty slow over time, or possible a page with a lot of validation.


Recreating controls is fast so you don't have to worry about speed

What you can do is create small method's like


void CreateTextBox(Panel pnl)
{
   TextBox text = new TextBox();

   pnl.Controls.Add(text);

}


Then simply call this method

CreateTextBox(PnlID);


Every time you need to create the control.

I could be wrong maybe there is a way.. But i doubt it.


I assumed there was no way, but I figured it wouldn't hurt to ask :-)

Currently I have a Global Variable which holds an array for every page on the site, I was thinking of adding the controls to this system, so I can skip a bunch of code that doesn't need to be re-created. I am using a Hash table to store access the arraylist, to avoid the issue of lookup time, so this will be my code on page init:

OnInit()
{
  if(null==HashtableName[Request.Url.AbsoluteUri])
  {
    //Add one spot to the ArrayList of Data

    //Then I will associate that index to the new name in the hash table:
    HashtableName.Add(Request.Url.AbsoluteUri, ArraListName.Count - 1)
    
    //Add Validation stuff (generated javascript and controls) class to the arraylist
  }

  //Add the stuff from my stored data instead of creating it all then adding it
  AddCahcedData(HashtableName[Request.Url.AbsoluteUri]);
}



do you think it will be worth it? I am trying to create the cleanest/fastest system possible of adding pages and setting up validation.
Was This Post Helpful? 0
  • +
  • -

#4 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Persisting Dynamically Created Content

Posted 29 April 2011 - 01:15 PM

I think its best you create you controls on an aspx page,
you can cache that page ..

It will give you less headaches

AKA: *** Banging you head against the table **** :)

And in the end of it all the C# code will do the same thing as just putting in the controls in aspx page.

It might be worth looking Look at some tips on the internet for speed improvement..

Hope this points you in the right direction ..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1