update cookie from webmethod (PageMethod) using ajax

Last post 08-29-2008 10:53 AM by shyamasndr. 2 replies.

Sort Posts:

  • update cookie from webmethod (PageMethod) using ajax

    08-29-2008, 8:13 AM
    • Member
      174 point Member
    • shyamasndr
    • Member since 03-21-2007, 2:14 AM
    • Bangalore
    • Posts 29

    I have one requirement  where I want to update cookie from a webmethod. The webmethod is called from ajax using PageMethods.

    Here is how my .aspx page looks like

    In code behind

    [webmethod]

    public static void updateCookie(string arg1)

    {

    //some code to update cookie

    }

     

    in javascript I call the method using ajax

    PageMethods.updateCookie(arg1, OnSuccess, OnError, OnTimeout)

    but this does not updates cookie. Is their any way to update cookie from webmethod?

    Shyamasundara K
  • Re: update cookie from webmethod (PageMethod) using ajax

    08-29-2008, 8:41 AM
    Answer
    • Contributor
      5,903 point Contributor
    • Sharbel_
    • Member since 11-12-2002, 8:02 AM
    • Windsor, Ontario
    • Posts 1,181

     I dont believe this is possible serverside, however, why not set the cookie in the OnSucess javascript method, with the key/value provided from the web-method?

  • Re: update cookie from webmethod (PageMethod) using ajax

    08-29-2008, 10:53 AM
    Answer
    • Member
      174 point Member
    • shyamasndr
    • Member since 03-21-2007, 2:14 AM
    • Bangalore
    • Posts 29

    Yes!  It is possible from server side if I remove line 'throw ex' code in the below code. but I was trying to update the cookie on error in webmethod. Something likes this.

    try
    { 
    
    }
    catch(Exception ex)
    {
       HttpContext.Current.Response.Cookies[“ck”].value=”value”;
       throw ex;
    }
    
     

    On this scenario it is not updating. Thanks for your quick response.

     

    Shyamasundara K
Page 1 of 1 (3 items)