• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Webpage loading sequence process

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
MikeCombe
Asked:
MikeCombe
  • 3
  • 2
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
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
 
MikeCombeAuthor Commented:
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
 
Scott Fell, EE MVEDeveloperCommented:
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
 
MikeCombeAuthor Commented:
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
 
Scott Fell, EE MVEDeveloperCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now