在传递参数的时候,如果登陆按钮为图片按钮,
  <asp:ImageButton ID="btn_Login" runat="server"  ImageUrl="/images/Login.gif" OnClick="btn_Login_Click"  />
那么就返回false
如果改为 
     <asp:Button ID="btn_Login" runat="server" Text="LGNIN" OnClick="btn_Login_Click" />
就正常了
想问一下,如果是图片按钮的话,我该怎么操作参数,谢谢
  bool Login(string toUrl, string UerName, string UserPass)
        {            string viewState = "/wEPDwUKMTEyMTc3MTQwNmRkIculFbfWMX1/yR0BZI2VFcDp6eQ=";
            string eventValidation = "/wEWBALT9NqvDAL3xJvhBALS9cL8AgKDkOvcBKSwueZ1M2sySwc3iMeiEuMmAOyw";
            string submitButton = "LGNIN";            string toData = "txt_UserName=" + HttpUtility.UrlEncode(UerName) + "&txt_UserPass=" + HttpUtility.UrlEncode(UserPass) + "&btn_Login=" + HttpUtility.UrlEncode(submitButton);
            toData += "&__VIEWSTATE=" + HttpUtility.UrlEncode(viewState) + "&__EVENTVALIDATION=" + HttpUtility.UrlEncode(eventValidation);            byte[] data = System.Text.Encoding.UTF8.GetBytes(toData);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(toUrl);
            HttpWebResponse response;
            try
            {                request.Method = "POST";
                request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
                request.Referer = toUrl;
                request.Headers.Add("Accept-Language", "zh-cn");
                request.ContentType = "application/x-www-form-urlencoded";
                request.Headers.Add("Accept-Encoding", "gzip, deflate");
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
                request.ContentLength = data.Length;
                request.CookieContainer = m_Cookie;                Stream newStream = request.GetRequestStream();
                newStream.Write(data, 0, data.Length);
                newStream.Close();                response = (HttpWebResponse)request.GetResponse();
                m_Cookie.Add(response.Cookies);                //Stream stream = response.GetResponseStream();
                //string WebContent = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd();
                //stream.Close();                if (m_Cookie.Count > 0)
                    return true;
                else
                    return false;            }
            catch (WebException ex)
            {
                response = (HttpWebResponse)ex.Response;
                m_Cookie.Add(response.Cookies);
                return false;
            }
            
        }

解决方案 »

  1.   

    本帖最后由 net_lover 于 2010-02-22 12:28:13 编辑
      

  2.   

    我在我的HTML代码中没有发现这2个ID,<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
    也没有发现 
    function __doPostBack(eventTarget, eventArgument)
      

  3.   

    问题解决了
    需要参数
    btn_Login.x=
    btn_Login.y=
    请问一下这2个参数是用来干嘛的?
      

  4.   

    btn_Login.x=
    btn_Login.y= 这2个参数标明你鼠标点击的点在图片上的位置