Monday, May 20, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  171] [ 7]  / answers: 1 / hits: 29555  / 11 Years ago, wed, january 22, 2014, 12:00:00

I want to set the Dropdown selected value in Session. I have done in Code behind. But for some condition i have to Do in Client Side Itself. i tried the following. but i did't solution yet.



<%Session[Test] = Welcome Mamu;%>  
var session_value='<%=Session[Test]%>';
alert(session_value);


The above work fine. Note that i have assign Static value(Welcome Mamu). but for Dynamatic,



var strTest=document.getElementById('DropDownList1').value;  
<%Session[Test] = '+ strTest +';%>


It is Working fine in Client Side. But i Server Side(Code Behind), the Session[Test] value is '+ strTest +'.



Is any other way to assign values to Session?


More From » c#

 Answers
62

Not possible to assign session values directly through javascript.



I found alternative ways. Call the code behind function and assign the session values.



Javascript Function:



 function InitializeRequest(path) 
{
// call server side method
PageMethods.SetDownloadPath(path);
}


[System.Web.Services.WebMethod]
public static string SetDownloadPath(string strpath)
{
Page objp = new Page();
objp.Session[strDwnPath] = strpath;
return strpath;
}


Must enable page methods set to true



<asp:ScriptManager EnablePageMethods=true ID=MainSM runat=server ScriptMode=Release LoadScriptsBeforeUI=true></asp:ScriptManager>


[#73016] Tuesday, January 21, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devonw

Total Points: 311
Total Questions: 116
Total Answers: 111

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;