locked
adding values to Session in InLine WEBMETHOD RRS feed

  • Question

  • User-1908415729 posted

    Hi All,

    By using AJAX am trying to call a webmethod in Code behind. In that webmethod I want to put some dynamic grid data and text box data to session. But WEBMETHOD is static, so we wont get access to Session and web controls. Is there any other method to achieve that goal.

    in window.onbeforeunload  calling a script, that script calls a webmethod. This is the procedure i am following.

    Thanks & Regards,

    Prasad

    Saturday, January 29, 2011 12:12 AM

Answers

  • User1867929564 posted

    We can send the parameters, but we cant do validation in codebehind (aspx.cs) file. 


    there are so many ways.We can do validation before sending it to webmethod using javascript and display message.

    we can also validate inside webmethod using validator or regex.
    but using javascript is easy.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 2, 2011 7:29 AM

All replies

  • User1224194097 posted

    in window.onbeforeunload  calling a script, that script calls a webmethod

    I am assuming that PageMethod is being called in beforeunload event. If that is the case, you can pass textbox text as a parameter for the method. Then, you can save the value in session. Similarly, you can pass the InnerHTML of the Grid as another parameter.

    Saturday, January 29, 2011 7:18 AM
  • User-1908415729 posted

    Hi Santhosh,

    Thanks for the reply. Ya we can pass the text box values as parameter but we wont get access to "Session" in static method. How can I achieve this.

    Thanks & Regards,

    Prasad


    Saturday, January 29, 2011 11:55 AM
  • User712082397 posted

    If C#, use  this to decorate your web method:

    [WebMethod (EnableSession = true)]

    If VB.NET:

    <WebMethod(EnableSession:=True)> _
    

    References: http://msdn.microsoft.com/en-us/library/aa480509.aspx

    http://weblogs.asp.net/stevewellens/archive/2009/04/05/using-session-state-in-a-web-service.aspx

     

     

    Monday, January 31, 2011 1:08 PM
  • User-1908415729 posted

    Hi sachingusain,

    Thanks for the reply. I have one more doubt, Can we get textbox values inside webmethod.


    Thanks & Regards,

    Prasad

    Tuesday, February 1, 2011 12:17 AM
  • User-1908415729 posted

    Hi sachingusain,

    Session is not available in InLine WebMethod even if i include EnableSession=true. That is code behind (aspx.cs) file.


    Thanks & Regards,

    Prasad

    Tuesday, February 1, 2011 12:32 AM
  • User1791120482 posted

    Hi Prasad,

    You cannot access a control and thus its value in a static page webmethods.  Alternatively you can pass the textbox value as a Parameter to the webmethod itself.

    Regards,

    -Sekhar 

    Tuesday, February 1, 2011 1:07 AM
  • User1867929564 posted

    This may or may not related to ur problem.
    In web staticmethod you can access whatever you want by,
    first create object of page class ,
    public partial class ChangePassword

    In my web method,I create its object
    ChangePassword obj=new ChangePassword();
    now with obj I can do whatever.

    Try this and share ur experience.

    Tuesday, February 1, 2011 3:58 AM
  • User-1908415729 posted

    Hi Sekhar,

    We can send the parameters, but we cant do validation in codebehind (aspx.cs) file.

    For Ex Zip textbox should contain a valid zip(fetches the valid zip from DB). If its not valid then it should display an error message. These I cant do in static method.

    Thanks & Regards,

    Prasad

    Wednesday, February 2, 2011 6:31 AM
  • User-1908415729 posted

    Hi Kumar Harsh,

    Yes we can create an object of the same code behind.  Creating a new object, makes the control values to null. Soits not possible.


    Thanks & Regards,

    Prasad

    Wednesday, February 2, 2011 6:34 AM
  • User1867929564 posted

    Your problem appear simple to me.
    However if none of solution working then you need to explain your requimrent step by step again.

    you want to access already created session or create new session inside webmethod.

    Wednesday, February 2, 2011 7:25 AM
  • User1867929564 posted

    We can send the parameters, but we cant do validation in codebehind (aspx.cs) file. 


    there are so many ways.We can do validation before sending it to webmethod using javascript and display message.

    we can also validate inside webmethod using validator or regex.
    but using javascript is easy.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 2, 2011 7:29 AM
  • User1791120482 posted

    I agree with KumarHarsh.   Javascript is ideal way of doing validation in your scenario.  Do the validation and if it validates then make a WEBMETHOD call.

    This should do the job for you.

    Regards,

    -Sekhar 

    Thursday, February 3, 2011 12:16 AM