js在调用C#定义的pagetop类的时候总提示不存在怎么办?
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="pagetop.ascx.cs" Inherits="pagetop" %>
<script type="text/javascript">
window.status='郁闷了pagetop未定义是怎么回事啊?';
function addfavorite(url,title,topicid)
{
external.AddFavorite(url,title)
pagetop.Collection(topicid);
return false;
}
</script>
上面是axcs内的js代码,下面是类pagetop.ascx.cs
当js一执行的时候就提示pagetop未定义,请知道是那里的原因?
using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.Web.Services.Protocols;
public partial class pagetop : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_pagetop));
//Cookie登陆
if (Session.Contents["username"] == null && Request.Cookies["xxxxxx"] != null)
{
Session.Contents["username"] = Request.Cookies["xxxxxx"].Value;
Response.Cookies["xxxxxx"].Value = Request.Cookies["xxxxxx"].Value;
Response.Cookies["xxxxxx"].HttpOnly = false;
Response.Cookies["xxxxxx"].Expires = DateTime.Now.AddYears(1);
SqlStore.SqlUserCookie(Request.Cookies["xxxxxx"].Value);
}
}
[AjaxPro.AjaxMethod]
public string AddCookie(int topicid, string title)
{
SqlStore.SqlAjax(topicid, 5, "");
System.Web.HttpCookie newcookie = HttpContext.Current.Request.Cookies["topicid"];
if (newcookie == null) newcookie = HttpContext.Current.Response.Cookies["topicid"];
if (newcookie.Values.Count >= 50)
return "false";
newcookie.Values[topicid.ToString()] = HttpContext.Current.Server.UrlEncode(title);
newcookie.Expires = DateTime.Now.AddYears(1);
HttpContext.Current.Response.AppendCookie(newcookie);
return "true";
}
}
------解决方案--------------------
AjaxPro.Utility.RegisterTypeForAjax(typeof(_pagetop));
这句