Pagemethod出现循环多重访问问题 [英] Pagemethod having issues with looped multiple access

查看:155
本文介绍了Pagemethod出现循环多重访问问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上有一张图片列表.我正在尝试检查,网站上是否有所有图像.因此,我在gridview中绑定了图像列表.然后在按钮中单击我需要检查图像的存在.如果这是异步发生的,那么对用户来说将是一件好事.
因此,我尝试在AJAX中使用Pagemethod.我从Javascript触发Page方法函数,如下所示,
Default.aspx

I have a list of images in a web site. I am trying to check, is all images is there in the web site. So I have binded list of images in gridview. Then in button click I need to check the existance of image.If this happens asynchronously then it will be good to user.
So I tried to use Pagemethod in AJAX. I trigger Page method function from Javascript as follows,
Default.aspx

var lbl='Label';
function getDate() {
for (var x = 1; x < 10; x++)
{
lbl=lbl+x;
document.getElementById(lbl).innerText='Loading...';
PageMethods.GetData(x),OnSucceeded,OnFailed);
}
}
// Callback function invoked on successful
// completion of the page method.
function OnSucceeded(result, userContext, methodName)
{
var Arr=result.split('`');
Arr[0]='label'+Arr[0];
document.getElementById(Arr[0]).innerText = Arr[1];
}
// Callback function invoked on failure
// of the page method.
function OnFailed(error, userContext, methodName)
{
document.getElementById('label').innerText = 'Error occured';
}



Default.aspx.cs



Default.aspx.cs

[System.Web.Services.WebMethod]
    public static string GetData(string IO)
    {
        string str, url;
        url = 'http://www.samplesite/images/'+IO+'gif';
        try
        {
            System.Net.HttpWebRequest webrequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
 
            System.Net.HttpWebResponse myresponse = (System.Net.HttpWebResponse)webrequest.GetResponse();
            if (myresponse.StatusCode == System.Net.HttpStatusCode.OK)
                str = "True";
            else
                str = "False";
        }
        catch (Exception e)
        {
            if (e.Message.Contains("404"))
                str = "False";
            else
                str = "Error";
        }
        return (IO + "`" + str);
    }


我的问题是,如果我执行此执行,则它对于x小于30或40可以正常工作.我的站点中有100多个图像.如果x超过50,则分页方法无法正确响应.

在这方面请提供帮助.


My issue is if I have this execute it works fine for x is less than 30 or 40. I have over 100 images in the site. If x exceeds 50 then pagemethod doesnot respond appropriately.

Kindly help in this regard.

推荐答案

最后找到了罪魁祸首.是我,:)
Finally got the culprit. It''s me, :)
finally
  {
    if (myresponse != null) myresponse.Close();
  }



Default.aspx.cs



Default.aspx.cs

<code>
[System.Web.Services.WebMethod]    
public static string GetData(string IO)    
{        
  string str, url;        
  url = ''http://www.samplesite/images/''+IO+''gif'';      
  try
  {        
    System.Net.HttpWebRequest webrequest = (System.Net.HttpWebRequest) System.Net.HttpWebRequest.Create(url);       
    System.Net.HttpWebResponse myresponse = (System.Net.HttpWebResponse)webrequest.GetResponse();            
    if(myresponse.StatusCode==System.Net.HttpStatusCode.OK)       
       str = "True";            
    else
       str = "False";        
  }
  catch (Exception e)        
  {          
   if (e.Message.Contains("404"))              
     str = "False";            
   else
     str = "Error";        
  }     
  finally
  {
    if (myresponse != null) myresponse.Close();
  }

  return (IO + "`" + str);    
}
</code>


我尚未在我的网络方法中关闭我的HttpWebResponse,这引起了混乱. Pagemethod在这里没有任何事可做.对不起,小姐导致了这个问题.学习了以所有可能的方式解决问题"的课程,而不是一心一意.感谢Sandeep和Abhinav.


I have not closed my HttpWebResponse in my web method, which made this confusion. Pagemethod doenot have nothing to do here. Sorry for miss lead this issue. Learned a lesson "Approach the issue in all possible ways" and not in a single minded. Thanks to Sandeep and Abhinav.


这篇关于Pagemethod出现循环多重访问问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆