?
Solved

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

Posted on 2011-02-15
6
Medium Priority
?
309 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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

765 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