Solved

Webpage loading sequence process

Posted on 2012-12-22
5
253 Views
Last Modified: 2012-12-27
I believe a webpage loading sequence process is...
   1. code-behind code
   2. webpage scripts, html, etc

Is there a way to  run a "code-behind sub" as the very last thing before a webpage is displayed
Something like....
   1. code-behind code
   2. webpage scripts, html, etc
   3. code-behind code (special)


The probelm I am encountering is:
I use code-behind to set a  session variable, Session("myVariable")
It appears that this value is set during code-behind and before the webpage scripts are loaded. I need to grab a value of a dropdown list <asp:DropDownList and use it in my code-behind sub.
0
Comment
Question by:MikeCombe
  • 3
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 38716035
You are correct.  Serverside code (code behind) runs first.  Then html including any generated html from your server side scripting.  Finally any client side scripting (javascript).  Without running a page refresh, you can't go back and run client side scripting.

A) Some options are to calculate everything you need with server side scripting.

B) Process what you need via ajax

c) Rely on javascript/jquery to place value of what you need in one spot to another and possible calculations as well.

Depending on what you are actually doing, it sounds like option B may be for you.  Can you describe in more detail or use some very shortened code examples of what you have and what you want to end up with?
0
 

Author Comment

by:MikeCombe
ID: 38716072
Thanks. That's what I thought.

I posted a corollary question entitled:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Is this possible? Calling a sub in a Child webpage from the Master webpage
ID = 27976154

I am using a MasterPage & a default.aspx page

The MasterPage contains a <asp:DropDownList control.
When this ddl changes, it fires this sub:
 Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As [Object], ByVal e As EventArgs)

I have a sub in Default.aspx code-behind that uses the value set in the <asp:DropDownList control DropDownList1. The sub name is doStuff_default()

Is there a way to call the sub doStuff_default() from the MasterPage code-behind DropDownList1_SelectedIndexChanged ?

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Here's what I am trying to do.
1. Populate a DataTable, using the value of a DropDownList as a filter.
2. Display the data on the webpage.

Display on the webpage occurs this way:
<div id="div1" class="div1_Position" runat="server"><%=Session("dt_myList")%></div>
Note: Session("dt_myList") is set in the code-behind code.

When I embedded the DataTable code in the html, it worked ok (at first).
When I moved the "Populate a DataTable" to code-behind, I lost the immediate reference to the DropDownList

The reason I moved the "Populate a DataTable" to code-behind was because...
when it was in embedded html, I started to get "duplicate" entries into the DataTable. Instead of getting something like: 1,2,3,4,5 ..... I would get: 1,1,2, 1,2,3, 1,2,3,4, 1,2,3,4,5
I thought I might have some cross-code interfering with the "Populate a DataTable" so I moved it to code-behind. It solved the "duplicate" issue, but presented the "delay" issue on reposting from changes in the DropDownList.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38716112
I 'm still classic asp.  But why are you using a session variable for this?  

If the selection from the drop down is supposed to update your data table, then you need to put the dropdown list in a form, then submit the form with the data from the selected drop down which runs your asp code and produces the updated page.

If you want to use the dropdown without a submit button, then you use javascript/jquery to detect the change, send a post and do the updated.  

The only reason to use the session variable is to pass the data from one page to another that is not related by submitting a post or get.
0
 

Author Comment

by:MikeCombe
ID: 38716133
not really.

asp.net does auto post back...there is no need for a submit button or javascript.

"normally" your definition of using a session variable is correct.
However, I am using it (the session variable) to post code from a code behind sub onto the aspx webpage. I am doing that directly into a <div> because other factors are involved (css formatting, display rotation, etc)

Other factors I am exploring are the relationship between the Master/Client webpage and the ability to call subs (from Master to a Client webpage sub). These were not present in classic asp.

Thanks for your input !!
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 38716156
I think this year I am going to make it a point to learn asp.net.  


When you say you are using the session variable to manage css formatting,  I would save that for javascript.   Send the data from your server side which  creates rendered html  <p>hello world</p>.  Then after the page loads, use javascript/jquery to <p class="xyz">hello world</p>.   Or throw <li>line1></li><li>line2></li><li>line3></li> into an array, randomize and come out as <li>line3></li><li>line1></li><li>line2></li> although that can be done server side as well.  

Hopefully somebody else with .net experience will chime in.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now