aspx页面<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" Debug="true" %><%@ Register Assembly="YH.PromptBox" Namespace="YH.PromptBox" TagPrefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript" defer="defer">
function init()
{
setInterval("show()",1000);
}
function show()
{
Default.Get();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<cc1:PopupWin ID="PopupWin1" runat="server" HideAfter="-1" />
</form>
</body>
</html>
cs文件
using System;
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.Data.SqlClient;public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Default));
Get();
}
} [AjaxPro.AjaxMethod]
public void Get()
{ string strConnection = ConfigurationManager.AppSettings["sqlconn"].ToString();
SqlConnection conn = new SqlConnection(strConnection);
conn.Open();
SqlCommand cmd = new SqlCommand("select * from a where a='嗷嗷嗷'", conn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
msg = reader["a"].ToString();
this.PopupWin1.AutoShow = true;
reader.Close();
}
else
{
this.PopupWin1.AutoShow = true;
msg = "欢迎回来!";
reader.Close();
}
conn.Close();
}
}我就想用AJaxPro定时调用我的Get()方法,这样写对吗?本人实在是技术菜,老发帖,不好意思了,麻烦各位解答
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript" defer="defer">
function init()
{
setInterval("show()",1000);
}
function show()
{
Default.Get();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<cc1:PopupWin ID="PopupWin1" runat="server" HideAfter="-1" />
</form>
</body>
</html>
cs文件
using System;
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.Data.SqlClient;public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Default));
Get();
}
} [AjaxPro.AjaxMethod]
public void Get()
{ string strConnection = ConfigurationManager.AppSettings["sqlconn"].ToString();
SqlConnection conn = new SqlConnection(strConnection);
conn.Open();
SqlCommand cmd = new SqlCommand("select * from a where a='嗷嗷嗷'", conn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
msg = reader["a"].ToString();
this.PopupWin1.AutoShow = true;
reader.Close();
}
else
{
this.PopupWin1.AutoShow = true;
msg = "欢迎回来!";
reader.Close();
}
conn.Close();
}
}我就想用AJaxPro定时调用我的Get()方法,这样写对吗?本人实在是技术菜,老发帖,不好意思了,麻烦各位解答
Get()返回类型是void的,不知道想获取什么的
function init()
{
setInterval("show()",1000);
}
function show()
{
Default.Get();
}
</script>据我所知 这样写没有问题,但 有一点,实际应用中 可能是缓存问题, Default.Get(); 应该只执行了一次吧,你在 Default.Get(); 中加一个随机数 例如 Default.Get(Math.random());
中不需要添加Get()方法Get()属于无返回值类型,所以不能有输入返回值Ajapro中不可以引用页面控件的ID
msg是控件里的一个属性,我封装成自定义控件了,就是那个cc1标签开头的
这个我调试了,既不报错,也不出我想要的效果,才上来提问的
哦,对了,还有,web.config里也要设置,如果不好使的话,要看一下web.config。还有就是ajaxpro要使用.ashx,有一次,我自己也要用.ashx,在global里面拦截了一下.ashx的页面,结果也不好使了。
{ string strConnection = ConfigurationManager.AppSettings["sqlconn"].ToString();
SqlConnection conn = new SqlConnection(strConnection);
conn.Open();
SqlCommand cmd = new SqlCommand("select * from a where a='嗷嗷嗷'", conn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
msg = reader["a"].ToString();
this.PopupWin1.AutoShow = true; reader.Close();
}
else
{
this.PopupWin1.AutoShow = true; msg = "欢迎回来!";
reader.Close();
}
conn.Close();
}
不能这么写的你要想想,在使用ajax的时候,他是不刷新页面的,所以当你前台的show方法被执行,就算你的后台操作了服务器控件,可是没有刷新,你做的操作是不会显示的,也就是无效的
这就是我的自定义控件在源里面的显示:<cc1:PopupWin ID="PopupWin1" runat="server" HideAfter="-1" /> 不知道你要什么样的?
我把提示框放在一个Div里,能定时刷新这个DIv吗?
代码可以,
web.config 配置中要加入以下配置
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers></system.web>
我这破系统什么版本的MSN都安装不上
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;public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Default2));
} [AjaxPro.AjaxMethod()]
public string close()
{
return "close";
}
}
var a=Default2.close().value;
document.getElementById("close").innerHTML="sss";JS错误:Default2未定义,但是我已经注册了,并且在配置文件中添加了
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
</httpHandlers>