Passing a value from server side to client side without postback

My problem exactly is that on my aspx.vb code-behind, I can update the field using

HiddenField ID = "hidSessionTimeout"

 Code-Behind: on Page_Load

hidSessionTimeout.Value = HttpContext.Current.Session.Timeout

 on ChangeTimeOutValue()

hidSessionTimeout.Value = 5

 Client-Side:

 var x= document.getElementById("hidSessionTimeout");

 

It seems that the javascript cannot get the latest updated value... Any ideas?

 

0
geljian_a
9/2/2008 9:22:16 AM
asp.net.client-side 24353 articles. 1 followers. Follow

7 Replies
1139 Views

Similar Articles

[PageSpeed] 22

 

Any Workaround solution?
0
geljian_a
9/2/2008 9:59:16 AM

did u keep the page load code in if(!IsPostBack)


pavankumar
0
pavankumarkavety
9/2/2008 11:16:49 AM

geljian_a:

 Client-Side:

 var x= document.getElementById("hidSessionTimeout");

 

It seems that the javascript cannot get the latest updated value... Any ideas?

Have you tried:

var x = document.getElementById("hidSessionTimeout").value;


"If you have knowledge, let others light their candles in it."
— Margaret Fuller
0
mvang
9/2/2008 2:02:10 PM

 @pavankumar: I use the page to be inherited by all webforms

Codebehind:

    Public Class ParentForm
        Inherits System.Web.UI.Page

        Private sessionTimer As New System.Timers.Timer
        Private hidSessionTimeoutValue As Integer
        Private ScriptKey As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim timeout = HttpContext.Current.Session.Timeout

            hidSessionTimeout.Value = timeout
            hidSessionTimeoutValue = timeout
            Session("SessionTimeout") = timeout

            sessionTimer.Interval = 10000

            AddHandler sessionTimer.Elapsed, AddressOf TimerSessionEvent
            sessionTimer.Start()

            ScriptKey = Guid.NewGuid().ToString()

           
            Page.ClientScript.RegisterStartupScript(Me.GetType(), Guid.NewGuid().ToString(), "<script type='text/javascript' src='SessionIdle.js'></script>", False)
            Page.ClientScript.RegisterStartupScript(Me.GetType(), ScriptKey, "<script type='text/javascript'>SetSession(); windowonload()</script>", False)

        End Sub

        Private Sub TimerSessionEvent(ByVal source As Object, ByVal e As Timers.ElapsedEventArgs)
            Call Add()
        End Sub

        Private Sub Add()
            hidSessionTimeoutValue = hidSessionTimeoutValue - 1
            hidSessionTimeout.Value = hidSessionTimeoutValue

            Session("SessionTimeout") = hidSessionTimeoutValue
            
            If hidSessionTimeoutValue = 0 Then
                sessionTimer.Stop()
            End If
        End Sub

    End Class

 

Javascript: SessionIdle.js

 

var idle = true;
var idleSeconds = 0;
var idleSecondsMax = 10; // timeout if idle for 10 seconds
var sessionTimeout;
var sessionWarning = 18; // 18 minute/s before session timeout
var setIntervalId;
var sessionVariable;

function windowonload()
{
    //setIntervalId = window.setInterval("DetectIdle()", 1000); //every 1 second   
}

function DetectIdle()
{   
    var date = new Date()
    var min = date.getMinutes()
    var sec = date.getSeconds()
    if(idle)
    {
        if (idleSeconds > idleSecondsMax)
        { 
            alert("Idle: " + min + ":"+ sec);
            window.clearInterval(setIntervalId);
            IdleReset();
        }
    }
    else
    { 
        idle = true;
    }
    idleSeconds++; 
}

function IdleReset()
{
    idleSeconds = 0;
    idle = false;
}

function document.onmousemove()
{
    IdleReset();
}

function document.onkeypress()
{
    IdleReset();
}

function DetectSession()
{
    sessionTimeout = document.getElementById('hidSessionTimeout').value;
    if (sessionTimeout == sessionWarning)
    {
        alert("Session is about to expire");
    }
    if (sessionTimeout == 17)
    {
        alert("Session Expired");   
    }
}
function SetSession()
{   
    sessionTimeout = document.getElementById("hidSessionTimeout").value;
    window.setInterval("DetectSession()", 10000); //every 10 seconds
}

@mvang: I tried to use

sessionTimeout = document.getElementById("hidSessionTimeout").value;

var x = document.getElementById("hidSessionTimeout").value;

It only gets the value from the first value set during the page_load..The value is always 20.

 

 

0
geljian_a
9/2/2008 7:55:49 PM

I just noticed the title to this thread:

Passing a value from server side to client side without postback

If this is what you are attempting to do, your only other option is to use AJAX. Search Google for literally tons of examples.

NC...

0
NC01
9/3/2008 3:41:02 PM

 

The current project I am working on is not AJAX enabled. Or as much as possible, I should not use any AJAX controls.
0
geljian_a
9/4/2008 1:00:37 AM

Well then the only way would be with a PostBack.

 Client-side
 <script type="text/javascript">
 <!--
 __doPostBack('SomeTarget', 'Some value');
 // -->
 </script>

 Server-side
 private void Page_Load(object sender, System.EventArgs e)
 {
  // Insure that the __doPostBack() JavaScript method is created...
  this.GetPostBackEventReference(this, string.Empty);

  if ( this.IsPostBack )
  {
   string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];
   string eventArgument = (this.Request["__EVENTARGUMENT"] == null) ? string.Empty : this.Request["__EVENTARGUMENT"];

   // eventTarget == "SomeTarget"
   // eventArgument == "Some value"
  }
  else
  {
  }
 }

NC...

 

0
NC01
9/4/2008 11:11:32 AM
Reply:

Similar Artilces:

How to pass the client side values to server side?
 hello to All,Actually i wanna implement a code like... a string in HTML textbox retrieve in server side control....suppose i hv a HTML control <input type="text" id="txtHTML"/>, and dis control  txtHTML.text="abc".now i want to retrieve dis client side string "abc" in d server side textbox named "txtASP"...which hs a property runat="server"so please give me an idea how to pass values from client side to server side.... hope u understand a problem... sam.  You could do this <input type="text"...

How to pass values from client side to server side
Hi, Is there a way to transfer variable from a client loop to a server loop. For example: var clitest = 'test'; Now I would like to get test variable from javascript into a server string variable <% sertest = ?? %> I understand that this can be done by storing a variable into a hidden control for example and than access it using server side, but when I have to transfer an array for example it get's a little more complicated. I was wondering is there more efficient approach? You can't transfer arrays, only strings. To workaround this problem pass delimited stri...

passing client side variable value to server side
 i have a grid and  by click on the rows, the onrowclick event is fired on client side. I want to pass the row index to the server side. As there are not sessions variables in javascript so i am stuck to pass the row to the server side.. I have made a texbox and set its valueto the index in the onrowclick event but when refresh calls, the text box became empty as the value set is on client side, i want page to persistthe value,  How can i do that? Tel me some way passing the row index to the server side?? Hi, You can call GridView_SelectedIndexChanging event on row click ev...

how to pass values from client side to server side #2
Hi Guys....               This is Aani....I'm using ASP.NET in C# language.i have created one webpage for get input from user(from java script inputbox).i want that entered data in server side operations.how can i pass that value from client side server side.i need proper code in C# language.reply me soon... Thanks is Advanced... Regards....Aani plz use hidden field.ur assing values to text boxes through java script. before post back call a java scipt function to assign value to hodden fieed. even u can add these ...

Problem passing value client-side to server-side
I have a page that calls a pop-up while passing an encrypted value via a query string. The value is encrypted on the parent client-side in javascript so it needs to be decrypted client-side as well. This decryption occurs on closing the child (popup) and I am at a loss of when and how I should get this value to the server-side. On the popup you just want to process server side code? Anytime you can access for example the raw url:string raw = Page.Request.RawUrl;If you need to access any values on the client side you can access the url using javascript. Another idea is to, on the code beh...

Client side code to pass values to server side variable?
Hi there, I have ListBox_SelectedTextChanged() method that creates another list box in the runtime as follows: // Get Action Level List lbxActionLevel = new ListBox();lbxActionLevel.ID = "ddlA" + i.ToString(); lbxActionLevel.Width = 100; lbxActionLevel.Rows = 2;SqlDataReader dr = new BusinessLogicLayer().bllGetActionLevels(); lbxActionLevel.Items.Clear();while (dr.Read()) {ListItem lAction = new ListItem(); lAction.Text = dr.GetString(1).Trim();lAction.Value = Convert.ToString(dr.GetInt32(0)); lbxActionLevel.Items.Add(lAction); lbxActionLevel.SelectedIndex = 0; } I ...

How to pass param values from server side to client side scripts
Hi, I have a page containing a datagrid with a list of geographic positions of interesting places. Users can filter this grid. Clicking an item the system displays the place on a map using MS Virtual Earth map component that exposes a client side javascript api. My problem is that the filtering is done on server side, but the map runs on client side. So during page load, I need to create long strings containing complex javascript codes on the server side, and add it as an event handler attribute to my components. This causes a lot of problems, for exemple...

sending data from client side to server side without postback?
Hey guys, Im having a little bit of trouble to get this working in my page, i have some javascript in my page which displays rows selected from a dropdown list. asp dropdown just errors when i try to use selectedindexchanged and when i add runat="server" to the <select> the javascript doesnt fire off. so im trying to make the javascript store this value into something where its accessible by my backend code and my C# can pick it up (like a hidden text input or something), but at the moment it isnt working :(Code: <script type="text/javascript">function Sh...

Client-side values to server-side ?
Hi! My previous query is attached below: I have implemented the below mentioned implementation . 'listbox1' on 'webform1' shows all the values from 'webform2'. I have implemented it using javascript. I would like to know that to implement validation on 'webform1', I would require the values of 'listbox1' ,which are on the client-side , to move to the server-side . I think sending a querystring will be fine but how to implement it using javascript and code-behind(C#)? Your suggestion will be appreciated. Thanks and regards, ap.       My previous query: " I am stuck wi...

Client Side values to Server Side
What is the best way to transfer Client Side values to the Server side? For example I have a variable "var1" in javascript. var1 = "sample"; How can I acquire this value in the server side?  What is the best approach for this?  Barry to send the value to the server during a postback, you need to place the value in an input control.  You could consider using a hidden textbox for that purpose.Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/ In the JavaScrip...

server side control passing value of self in client side function
I have a server side dropdownlist control.It contains values as:"#00FFFF""#FF00FF""#FFFF00"When the selectedindex is changed by the client I want to assign the value of the dropdownlist to a <div id="example"></div> evelement.pseudo:document.getElementbyId('example').bgcolor=dropdownlist.valueHow can I do this? I think I somehow need to attach a function to my dropdownlist which passes its own value as a parameter to a function...any suggestions?Thanks!please mark answers as 'Answered' and post back solutions when you figure stuff out that isnt in the post already. You ...

Is it possible to call client side function from server side code without initial client request?
Atlas is great. I'm using timer to periodically check database changes on server to populate client side controls with new data. Is it possible to do it without a lot of client requests to server which takes a huge useless network traffic? Server should call client side function on all connected clients when, for example, 'database updated' event occurs on server. Thanks. Hi~ Just for your interest, I think you could have a look at Comet, many web IM like Gmail's embeded Gtalk and meebo.com are built on this architecture你好! Just FYI o_O...

How do I pass client side values to server side ones & vice versa
Hi, If I have some jscript that creates a value based on a users input, how can I pass that to a server variable? Many thanks@nt Hi! You can set that value to a hiddenfield (runat = server) on the client and then read it from server side like any other control. If this is not clear, please paste your code so I may help you better.Regards,ClaudioSimplicity: "the art of maximizing the amount of work not done." Thanks for your time crfenix,  I need to do something like below: Code behind:protected void Page_Load(object sender, EventArgs e) {strin...

How can I set client side values as server side values?
Hi, Can anyone tell me how I can get client side values such as document.referrer, navigator.appName etc... into server side scripts? There are some client side values I'd like to set as session vars and insert into the db? How do I go about this? Thanks for any pointers Davlon PS (I'm using powersite 7.1.0.300) Pass them as page parameters, e.g., http://myserver/myurl?document.referrer=whatever&navigator.appName=yadayada Then, in your server-side script, just loop through the document.value array and get these values. -- pbm_hopethishelps, Roy Kie...

Web resources about - Passing a value from server side to client side without postback - asp.net.client-side

HasOffers Customers and Partners Event - Postback 2013 Tickets, Seattle - Eventbrite
This is going to be an incredible event with some of the smartest people in user acquisition, publishing, and performance advertising. Look ...

GeekWire Calendar Picks: Postback 2015, Hack the Dot Seattle, and more
Fast-growing Seattle startup Tune is holding its annual marketing conference, Postback 2015, at Seattle Center July 23 – 24. At last year’s event ...

ASP.NET MVC Framework - Wikipedia, the free encyclopedia
Based on ASP.NET , ASP.NET MVC allows software developers to build a web application as a composition of three roles: Model , View and Controller ...

Bentours - Travel Specialist Australia - Hotels, Tours, Flights, Cruises & Packages in Scandinavia, Russia ...
Bentours is a leading Travel Agent based in Australia. We fulfill our client's dream to explore and discover amazing travel destinations.


Amitech Business Solutions
Amitech Business Solutions, Creative Technology Startup ventures , Innovative IT company of India, allevents.in trendround

Drink of the Week - Logicum
Logicum It's Logical to share Menu Skip to content Home Contests Food Recipes Drink of the Week Health Technology Sports Space World Day Weapons ...

Publishers
Login An Adworkz Publisher gets paid for driving sales and leads to Advertiser Campaigns. Browse the network to find a campaign that matches ...

Sitefinity 4 Calendar Widget Released!
August 28th, 2011 I work for a software firm in Fort Wayne, IN. For the longest time, we used Sitefinity 3 as our standard content management ...

Second state of the Belgian Twitosphere
On April 17, 2007 I published the first state of the Twitosphere in Belgium , my home country. With this new state of the Twitosphere I want ...

Resources last updated: 12/12/2015 12:44:07 AM