Avatar of MikeCombe
MikeCombe
Flag for United States of America asked on

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.
ASP.NET

Avatar of undefined
Last Comment
Scott Fell

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Scott Fell

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MikeCombe

ASKER
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.
Scott Fell

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.
MikeCombe

ASKER
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 !!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Scott Fell

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.