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">
        &nbsp;<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()方法,这样写对吗?本人实在是技术菜,老发帖,不好意思了,麻烦各位解答

解决方案 »

  1.   

    思路没啥问题的,可代码貌似有点看不明白的,没有看到msg在哪个地方定义的
    Get()返回类型是void的,不知道想获取什么的
      

  2.   

          <script language="javascript" type="text/javascript" defer="defer">
            function init()
            {
                setInterval("show()",1000);
            }
            function show()
            {
                Default.Get();
            }
    </script>据我所知 这样写没有问题,但 有一点,实际应用中  可能是缓存问题, Default.Get(); 应该只执行了一次吧,你在 Default.Get(); 中加一个随机数  例如  Default.Get(Math.random());
      

  3.   

    AJAXPROpage_load
    中不需要添加Get()方法Get()属于无返回值类型,所以不能有输入返回值Ajapro中不可以引用页面控件的ID
      

  4.   


    msg是控件里的一个属性,我封装成自定义控件了,就是那个cc1标签开头的
    这个我调试了,既不报错,也不出我想要的效果,才上来提问的
      

  5.   

    我并不想获取什么,只想定时调用我.cs文件中的Get()方法!
      

  6.   

    据我所知 这样写没有问题,但 有一点,实际应用中 可能是缓存问题, Default.Get(); 应该只执行了一次吧,你在 Default.Get(); 中加一个随机数 例如 Default.Get(Math.random());
      

  7.   

    我觉得是OK的。你也可以做个试验,返回一个当前时间。这样你不就能确定是否工作了吗。
    哦,对了,还有,web.config里也要设置,如果不好使的话,要看一下web.config。还有就是ajaxpro要使用.ashx,有一次,我自己也要用.ashx,在global里面拦截了一下.ashx的页面,结果也不好使了。
      

  8.   

    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();
        }
    不能这么写的你要想想,在使用ajax的时候,他是不刷新页面的,所以当你前台的show方法被执行,就算你的后台操作了服务器控件,可是没有刷新,你做的操作是不会显示的,也就是无效的
      

  9.   

    把你的自定义控件的html发出来我,我教你怎么弄。
      

  10.   


    这就是我的自定义控件在源里面的显示:<cc1:PopupWin ID="PopupWin1" runat="server" HideAfter="-1" />  不知道你要什么样的? 
      

  11.   

    对,是不刷新页面,我这个提示框是刷新页面才会弹出。。郁闷啊   
    我把提示框放在一个Div里,能定时刷新这个DIv吗?
      

  12.   


    代码可以,
    web.config 配置中要加入以下配置
    <system.web>
        <httpHandlers>
          <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
        </httpHandlers></system.web>
      

  13.   

    fuda_1985兄,能帮我看看么,我项目发你,很小的
      

  14.   

    我网站的后台全部是用的Ajaxpro。。后来我发现其实直接用updatepanle挺好的。
      

  15.   

    updatepanle不能实现我想要的效果
      

  16.   

    关键是我这里就能开这页面。还有msn。其它都看不了。刚掉网了。你把自定义控件显示出来后的那个html发我就行了。
      

  17.   

    朋友能上QQ吗? 加你号码  MSN也行
      

  18.   

    QQ没法上。msn:[email protected]
      

  19.   

    自定义控件是个DLL文件,在源里就是这样注册的<%@ Register Assembly="YH.PromptBox" Namespace="YH.PromptBox" TagPrefix="cc1" %>
      

  20.   

    悲剧啊,Win2003系统中还安不了新版的MSN  我在去找找
      

  21.   

    干脆弄个浮动层放在右下。这样弄起来简单点吧。每次有消息的时候就display="inline"出这个层。没有就不显示。
      

  22.   

    如果你的信息提示框不是winform的话。。要是winform的应该可以用js调用的。
      

  23.   

    恩,我也知道没必要弄这么复杂,能给出上面你说的层实现这样功能的代码么? 
    我这破系统什么版本的MSN都安装不上
      

  24.   

    出现了未定义的代码。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;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>