In script I set Session.
<script>
$(document).on('click', '.Pagination', function () {
'<%Session["Pagination"] = "' + $(this).attr('id') + '"; %>';
alert('<%=Session["Pagination"] %>');
});
</script>
Alert works.
I can't access When i want to session from code-behind
if (!string.IsNullOrEmpty(Session["Pagination"] as string))
{
string Val = Session["Pagination"].ToString();
Session["Pagination"] = null;
}
String Val equal to ' + $(this).attr('id') + '
I used to put the value in the hidden variable and this will be accessible in code-behind, anyway the session object is active in code behind you can set the variable to session successfully.
Advantage: Globally declared session strings are accessible in code-behind and you can use the variables by calling the property files
ASP
<asp:HiddenField id="session_obejct" runat="server" />
Javascript
document.getElementById('session_obejct').value = "Variable you want to set in session";
C#
session["SESSION_NAME"] = session_obejct.Value;
you can use other methods as well, I hope this will meet your requirement
I used this way and do it if one have better way pleas tell me
Javascript function:
<script>
$(document).on('click', '.Pagination', function () {
PageMethods.NumPagination($(this).attr('id'));
});
</script>
Code behind :
[System.Web.Services.WebMethod]
public static string NumPagination(string Num)
{
Page Pagination = new Page();
Pagination.Session["Pagination"] = Num;
return Num;
}
if (!string.IsNullOrEmpty(Session["Pagination"] as string))
{
string Select = "1";
Select = Session["Pagination"].ToString();
Session["Pagination"] = null;
}
LINK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With