Force a page to detach in client script - google-app-maker

We have a page that takes a while to load the first time. The second time it loads fine. We tried the following hack in the startup script:
var page = app.currentPage;
app.showPage(app.pages.bigForm);
app.showPage(page);
This hack does work, the page loads fast the first time it is accessed by the user. The screen does not flash between the loads. However, the bigform does not detach and the first time it is opened it does not execute the on-attach event. This event contains some code I would like to execute.
My questions:
is there a better way of doing this, basically pre-loading the page?
is there a way to force a detach of the page?

I would recommend to start from looking for causes of slow load. Most common reasons are:
Large number of widgets to render (this will cause rendering throttle)
There are no much things you can do in this case:
Split page into multiple pages
If you have widgets that you need to show conditionally you can use createChildren method is called option in panel's Performance Settings instead of particular widgets' visible settings
Heavy queries to server or big number of queries
To tune app's performance in this scenario you can try these tricks:
eagerly load some datasources on app start
Use datasource prefetches for relational data (this easy tweak usually gives huge performance boost)

Related

Application performance problem Asp.net

i am facing a big speed problem with my application..we have to go for production but it got push backed becoz of this speed issue..
In my application..i have a page which is the main and important page of whole application..
in this page user spend most of the time...
in this page i am using 6 to 7 javascript files and jquery plugins..
whole page is ajax based and will do the jquery validations...
in this page i have 3 update panels (nested)..one update panel contains one formview and
other will contain one grid and a 4 formviews(will make visible of user selection..4 of the won't come at time..depends on grid view item i will get visible..like grid view record is type one then type one formview will visible on the page)..one update panel is parent update panel..
each formview contains more than 10 controls..dropdowns will load on formview onload event from database loopup tables..
this page won't refresh at all..because ever thing is in update panels..
i can't set the view state to false because of update panels..
i have to make more than 5 database calls each time..
this page works fine at the beginning of application start..after some amount of time its getting slower and slower..the database calls are pretty fast at the beginning and getting very slow after some time...
i don't know how to debug this thing and how to find which one causes this problem....please help me...
Update:
my view state is growing from 35 kb to 160 kb..
and i tried fullpost back triggers for some controls in updatepanels.. but the view state not getting down..its stays like that..on a double or triple browser refresh it got back to 35 kb..is this the issue?? thanks for your replies and suggestions...
I can't really help you if you don't show your code (specifically, the code the runs the database queries that start to slow down), but I can make one (hopefully good) guess:
It sounds like you might not be disposing your database connections properly. Every time you open a connection to the database, make sure you either wrap it in a try/finally block (where .Close() is called in the finally block) or create it with a using block.
You should look into a tool like JetBrains dotTrace that allows your monitor performance on a granular level. Then you will be able to see what the actual cause of your poor performance is. You get a 10 day trial at the website I linked to.
after a very long testing i found the problem...its because of update panels...we should not use update panel for too many controls..I didn't know that and the only control we have in asp.net is update panel for ajax..that's why i used the updatepanels...please stop using updatepanels and try to use jquery..i suffered a lot with this issue...thanks for your support guys...

Problem with dynamic Tab creation

I create Tabs (almost 18) Dynamically in my ASP.net application and these tabs are taking lot of time to load. I create these tabs during the Page Load event and Tabs mostly contain user controls.
There is no order in which these tabs will be rendered as use has the choice of changing the order. Any ideas/suggestions to improve the performance?
Tab creation is according to the user login. each user had ther on number of tabs. mostly 18 tabs. these tab names, user control names, and itz creating order is geeting from DB.
ArrayList tablist = ms.GetMemberScreenTabs(ClientId,UserId);
Session["TabList"] = tablist;
how can i load this as faster as possible.
I have had to deal with slow pages that contain tabs.. but in my case it was because the generated page was way too large. The HTML alone was going up to 2mb with the viewstate and all. And then add all the scripts and images etc. The page will seem like it is loading very slow but in reality the server side time was quite nominal.
You should try tracing the page and see how much time it actually takes to render. That would remove the network out of the equation.
Then if needed, you can follow the general page speedup methods like enable gzip, move the viewstate to use session, consolidate scripts/css to single requests, enable caching, lighter images via handlers etc.
Sorry if this seems off topic.

How to update every second from db?

I have to build a site like an auction-site:
I Have a detail page from items where a countdown should run down.
In this page nearly every second a update must be possible without a postback for the user:
coundown must be reset
money of aucton must be updated
gridView with last bidders must be updated
What kind of timer should I use for the countdown?
How can I update every second from DB? ( Ajax? )
How can I update the values / gridView?
You can use an UpdatePanel with Ajax.
However, given the nature of "Internet weather," one second per update is pretty aggressive for that approach.
You might instead consider using Silverlight. You would have much more control that way, and could minimize the amount of data that needs to go over the wire. In fact, you could use long polling with raw TCP connections, to further increase scalability.
For the countdown, you can use the JavaScript timing events. To access the database, if you don't want postback then you indeed need to access the data service by using Ajax. To make things easier, I recommend that you take a look at any Javascript libary such as JQuery.
For the timer I would use Threading.Timer so this can count down uninterrupted in a separate thread. You could also use a TimerCallback delegate which would do the database processing. However, I would be wary about trying to query the database at such a rate.
I would advise you look at using Ajax Update Panel for updating the countdown section of the page alone so you don't have to refresh the entire page.

Options for Dynamic content in ASP.Net

What choices do I have for creating stateful dynamic content in an ASP.Net web site?
Here's my scenario. I have a site that has multiple, nested content regions. The top level are actions tied to a functional area Catalog, Subscriptions, Settings.
When you click on the functional action, I want to dynamically add content specific to that action. For example, when Catalog is clicked, I want to display a tree with the catalog folders & files, and a region to the right for details.
When a user clicks on the tree, I want a context sensitive details to load in the details region (like properties or options to manage the files).
I started with UserControls. They worked fine as long as I kept loading everything into the page, and never let one disappear. As soon as one disappeared, ViewState for the page blew up because the view state tree was invalid.
(I didn't want to keep loading stuff into my page because I don't want the responses to be too huge)
So, my next approach was to replace my dynamic regions with IFrames. Then instead of instantiating a UserControl, I would just change the source on my IFrame. Since the contents of the IFrames were independent pages I didn't run into any ViewState problems.
But, I'm concerned that IFrames might be a bad design choice, but don't fully understand why. The site is not public, so search engines aren't a concern.
So, finally to my question.
What are my options for this scenario? If I choose an Ajax Solution (jQuery), will I have to maintain my own ViewState? Are there any other considerations I should take into account?
Controls that are added dynamically do not persist in viewstate, and this is the reason that it doesn't matter if you use AJAX or iframes or whatever.
One possible work-around is to re-populate controls on postback. The problem with this, is the page life-cycle (simplified) is:
Initialize
LoadViewState
Load Postback Data
Call control Load events
Call Load event
Call control events
Control PreRender
PreRender
SaveViewState
Unload
What this means is the only place to re-add your dynamic controls is Initialize -- otherwise posted data (or viewstate information) is not loaded into that control. But often, because Viewstat/postback data isn't available yet in Initialize, your code doesn't have the information it needs to figure out which controls need to be added.
The only other work-around I've found in this situation is to use a 3rd party control called DynamicControlsPlaceholder. This works quite well, and persists the control information in viewstate.
In your particular case, it doesn't seem like there are that many choices/cases. Is it practical just to have all the different sets of controls in the page, and put them inside of asp:placeholder controls, and then just set one to visible, depending on what is selected?
Some other options:
Content only appears to be dynamic. You load enough controls on the page to handle anything and only actually show what you need. This saves a lot of hassle messing with view state and such, but means your page has a bigger footprint.
Add controls to the page dynamically. You've already been playing with this, so you've seen some of the issues here. Just remember that the place to create your dynamic controls for postbacks is in the Page_Init() event, and that if you want them to be stateful, you need to keep that state somewhere. I recommend a database.
you've got a number of different options, and yes, IFrames were a bad design choice.
The first option is the AJAX solution. And with that there's not really a viewstate scenario, it's just you're passing data back and forth with the webserver, building the UI on the fly as needed.
The next option is to dynamically add the controls you need for a given post, everytime. The way this would work, is that at the start of the page life cycle, you'd need to rebuild the page exactly as it was sent out the last time, and then dump out all the unneeded controls, and build just those that want.
A third option would be to use Master pages. Your top level content could be on the Master page itself, and have links to various pages within the website.
I'm sure given enough time, I could come up with more, but these 3 appeared just from reading your problem.
dynamic controls and viewstate don't mix well, as noted above - but that is a Good Thing, because even if they did the viewstate for a complex dynamic page would get so bloated that performance would diminish to nil
use Ajax [I like AJAX PRO because it is very simple to use] and manage the page state yourself [in session, database tables, or whatever works for your scenario]. This will be a bit more complicated to get going, but the results will be efficient and responsive: each page can update only what needs to change, and you won't be blowing a giant viewstate string back and forth all the time

Easy way to AJAX WebControls

I've got a web application that I'm trying to optimize. Some of the controls are hidden in dialog-style DIVs. So, I'd like to have them load in via AJAX only when the user wants to see them. This is fine for controls that are mostly literal-based (various menus and widgets), but when I have what I call "dirty" controls - ones that write extensive information to the ViewState, put tons of CSS or script on the page, require lots of references, etc - these are seemingly impossible to move "out of page", especially considering how ASP.NET will react on postback.
I was considering some kind of step where I override Render, find markers for the bits I want to move out and put AJAX placeholders in there, but not only does the server overhead seem extreme, it also feels like a complete hack. Besides, the key element here is the dialog boxes that contain forms with validation controls on them, and I can't imagine how I would move the controls and their required scripts.
In my fevered imagination, I want to do this:
AJAXifier.AJAXify(ctlEditForm);
Sadly, I know this is a dream.
How close can I really get to a quick-and-easy AJAXification without causing too much load on the server?
Check out the RadAjax control from Telerik - it allows you to avoid using UpdatePanels, and limit the amount of info passed back and forth between server and client by declaring direct relationships between calling controls, and controls that should be "Ajaxified" when the calling controls submit postbacks.
I recommend that you walk over to your local book store this weekend, get a cup of coffee and find jQuery in Action by Manning Press. Go ahead and read the first chapter of this 300 page book in the store, then buy it if it resonates with you.
I think you'll be surprized by how easy jQuery lets you perform what your describing here. From ajax calls to the server in the background, to showing and hiding div tags based on the visitor's actions. The amount of code you have to write is super small.
There are a bunch of good JavaScript libraries, this is just one of them that I like, and it really is easy to get started. Start by including a reference to the current jQuery file with a tag and then write a few lines of code to interact with your page.
Step one is to make your "dirty" pieces self contained user controls
Step two is to embed those controls on your consuming page
Step three is to wrap each user control tag in their own Asp:UpdatePanel
Step four is to ensure your control gets the data it needs by having it read from properties which check against the viewstate for pre-existing values. I know this makes your code rely on ugly global variables but it's a fast way to get this done.
Your mileage may vary.

Resources