Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET VB.NET
This is my WebMethod
 
<WebMethod(Description:="Fetch Nested Albums", EnableSession:=True)> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function moveImages() As Object
    Dim FileCount As Integer = _
        HttpContext.Current.Request.Form(
            HttpContext.Current.Request.Form.Count - 2)
End Function
When i try to call the web service from the .aspx page i get this error
 
"Index was out of range. Must be non negative and less than the size of the collection."
 
How can i access the request Object? I was not able to access the session object in the web method, so i had to add EnableSession:=True in the Web Method.
 
So is there any setting for the request Object too?
Posted 14-Dec-12 3:34am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
I see this line:
Dim FileCount As Integer =
        HttpContext.Current.Request.Form(
            HttpContext.Current.Request.Form.Count - 2)
If HttpContext.Current.Request.Form.Count is less than 2, then you try to take a form variable at place -1 (or -2, -3, ...).
  Permalink  
Comments
Member 7781963 at 14-Dec-12 8:42am
   
Is there something wrong?
ProgramFOX at 14-Dec-12 8:43am
   
I think HttpContext.Current.Request.Form.Count is less then 2.
Member 7781963 at 14-Dec-12 8:50am
   
Actually when i execute the same code on a button click in the page code behind, it works.
ProgramFOX at 14-Dec-12 8:54am
   
Sometimes, there're more than 2 form variables.
Sometimes, there're less than 2 form variables.
Member 7781963 at 14-Dec-12 9:04am
   
actually the main reason i am trying to do it in a web method is to avoid post back..any way i can do it in a button click in the code behind without the post back?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 274
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 PIEBALDconsult 200
4 BillWoodruff 174
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 14 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100