?
Solved

Webpage loading sequence process

Posted on 2012-12-22
5
Medium Priority
?
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 1500 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 53

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 53

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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