You must Sign In to post a response.
  • Category: .NET

    Get class name in .cs page

    hi all,


    how to use the below jquery code in c#

    $("div.panel button.close").on("click", function (e)

    on this event i want clear the c# session variable.

    So please tell me how to use the above line in .cs page

    div.panel button.close is the class name
  • #764471
    Hi rishe,
    You can do this in client side using AJAX json, try this:
    .aspx code:
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script>
    $("div.panel button.close").on("click", function (e)
    {
    $.ajax({
    type: "POST",
    url: "WebForm1.aspx/WebFormMethodName",
    dataType: "json",
    data: JSON.stringify({ szValue: 'John', szVAl2: 'Mac' }),
    contentType: "application/json; charset=utf-8",
    error: function (error)
    {
    alert("Operation failed!!!");
    }
    });
    });
    .cs code:
    using System.Web.Services;

    [WebMethod]
    public static string WebFormMethodName(string szValue, string szVAl2)
    {
    HttpContext.Current.Session["abc"] = "";
    HttpContext.Current.Session.Remove("abc");
    HttpContext.Current.Session.Clear();
    return "";
    }
    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764498
    You cannot clear the session from the client side.
    So you have to make server call.
    1. You may create WebMethod call that server side web method using ajax call. In that web method you can clear the session variables.
    2. You can create ashx handlers. In the handler you can clear the session.

    From the above two ways will help you to remove the session variables. You can use JQuery Ajax call for making server side call with out refreshing your page.

    By Nathan
    Direction is important than speed


Sign In to post your comments