Solved

Webpage loading sequence process

Posted on 2012-12-22
5
258 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 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can Angular be used with classic asp.net? 3 41
ASP.net Markup for Sub Menu 2 63
Best book for Internet security 4 52
Adding Rows to Grid 4 32
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 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