Products

Solutions

Learn More

Partners

Community

Blog

About

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to use Java Script to receive the Session DataHow to use Java Script to receive the Session Data
Previous
 
Next
New Post
1/20/2019 5:35 AM
 
Dear Dnn Guru

How can I use Java Script in client side in module .ascx file to receive Session data which transferred from other page when I develop the module. I tried the normal Java codes that usually used in .aspx file but not successful. I also tried to use server side page_load to get Session Data first.(this is successful), and then assign the data to one Label then use Java Script to get the data by using document.getElementById("LabelID").value, or by using <%=this.Session["TransferedData"] %> to receive Session Data in JavaScript. These efforts are not successful. Please help me to solve the problem.

Thanks in advance

Jimmy
 
New Post
1/20/2019 11:42 AM
 
Show us your code. We can't guess.

Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
www.dynamisys.co.uk
 
New Post
1/25/2019 1:50 AM
 
Dear Richard

The codes are as following:

I tried to use server side page_load to get Session Data first, and then assign the data to Label lblTesting. This is successful, The value is displayed on Lable.
The codebehind codes are as following:

protected void Page_Load(object sender, EventArgs e)
{
string comingStr = Convert.ToString(Session["Transfer"]);
if (comingStr != null)
{
lblTesting.Text = comingStr;
}
else
{
lblTesting.Text = "Not Coming";
}
}

But when I tried to use client side javascript to get the Session Data by document.getElementById("lblTesting").value and then displaied on html input control or on Label control, Its' failed. The page codes are as following:










I also tried to let the client side received the Session data directly. The javascript codes are as following:


Its'failed again.
 
New Post
1/25/2019 2:14 AM
 
Dear Richard
I tried to use server side page_load to get Session Data first, and then assign the data to Label lblTesting. This is successful.
protected void Page_Load(object sender, EventArgs e)
{
string comingStr = Convert.ToString(Session["Transfer"]);
lblTesting.Text = comingStr;
}
 
New Post
1/25/2019 3:51 AM
 
In an HTML page all ID's have to be unique. ASP.NET generates a client-side id that is derived from the name of the label control. That explains why document.getElementById("lblTesting").value does not work. The id lblTesting does not exist in the HTML.

To make this approach work you need to generate that fragment of the javascript and have the client side ID of the control plugged into it. Something like...

"var x = document.getElementById(" + lblTesting.ClientID + ").value...."

Similarly I would expect generated javascript from...

"var x = " + <%=this.Session["TransferedData"] %> + ";"

To work. Use your browser tools to see what actually ends up in the page and use that knowledge to re-adjust your code.


Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
www.dynamisys.co.uk
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to use Java Script to receive the Session DataHow to use Java Script to receive the Session Data


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.

Content Layout

Subscribe to DNN Digest

Subscribe to DNN Digest

DNN Digest is our monthly email newsletter. It highlights news and content from around the DNN ecosystem, such as new modules and themes, messages from leadership, blog posts and notable tweets. Keep your finger on the pulse of the ecosystem by subscribing.  

What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out