[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

asp.net - javascript - pass a value from a textbox on client into sessionvaraible...

Posted on 2011-02-15
6
Medium Priority
?
310 Views
Last Modified: 2012-05-11
on click of a link I need to pass a value from a textbox into a session varaible that can be used on the server...
0
Comment
Question by:GlobaLevel
[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
6 Comments
 
LVL 10

Author Comment

by:GlobaLevel
ID: 34898515
something like this...

------

<a href="http://localhost:1757/test/wait_new_1.aspx" target="_blank" onclick="return popCC(this);">send values</a>

<script language="JavaScript">
         
function popCC(url) {
  sessionvaraible = textbox1.text

}
</script>

0
 
LVL 13

Accepted Solution

by:
devlab2012 earned 2000 total points
ID: 34898829
Use LinkButton instead of a normal anchor tag and use its server side click event.

Or You have to submit the value to the server using AJAX. Here is the complete details.

Create a web method on the page, that will accept value and set the session variable on the server:

(You need to add "using System.Web.Services" at the top of the page).
Here is the server side code:
[WebMethod()]
public static void SetVariable(String value)
{
    Session[name_of_session_variable] = value;
}


Now add a script manager with EnablePageMethods set to true.

Now, add link as:

<a href="#" onclick="setSession();">Link text</a>

add javascript code as:

<script>

function setSession()
{
    var textVal = document.getElementById("<%=TextBox1.ClientID%>").value;
    PageMethods.SetVariable(textVal, setVariableSuccess);
}

function setVariableSuccess()
{
  //do nothing here
}

</script>
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34900023
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Author Comment

by:GlobaLevel
ID: 34900401
devlab...

with this...
    <WebMethod()> _
    Public Shared Sub SetVariable(ByVal textVal As String)
        Session("SessionUserFirstName") = textVal
    End Sub

I get this...
Cannot refer to an instance member of a class from within a shared method or shared member intializer without an explicit instance of the class
0
 
LVL 13

Expert Comment

by:devlab2012
ID: 34904616
Change the following line:
Session("SessionUserFirstName") = textVal

To:
HttpContext.Current.Session("SessionUserFirstName") = textVal
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 34910666
DevLab...Thank you!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

656 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