当前位置:编程学习 > C#/ASP.NET >>

求助AJAX相关

我的服务器是windows sever 2008+IIS7+Oracle 10g的64位机器。
页面要实现的功能是一个label每秒刷新一次 显示时间。
技术用的是AJAX的timer和UpdatePanel结果在本机调试好使,在服务器上调试也好使,但是登陆服务器的网站,进入这个页面就不显示时间,也不刷新。
我本机装的是vs2008+windowsXP+Oracle10g客户端 32位机器。
谁能帮我解答。 --------------------编程问答-------------------- 换台机子试试。 --------------------编程问答-------------------- 换了也不好使 --------------------编程问答-------------------- 这些控件真不是什么好东西..

你要是只显示时间还不如直接显示客户端的时间..

简单得很 --------------------编程问答-------------------- 我要用timer控件进行局部刷新,而且我做的是即时通信的消息发送、接收功能(要从数据库中进行读取),不单单是为了显示时间。 --------------------编程问答-------------------- 怎么写的
--------------------编程问答-------------------- 贴出相关代码来 --------------------编程问答-------------------- --------------------编程问答-------------------- sendmsg.aspx:

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:Timer ID="Timer2" runat="server" Interval="1001" OnTick="Timer2_Tick">
    </asp:Timer>
    <%--<asp:Timer ID="Timer1" runat="server" Interval="900" OnTick="Timer1_Tick">
    </asp:Timer>--%>
    <div>
        <table>
            <tr>
                <td>
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:ListBox ID="ListBox1" runat="server" Height="400px" Width="490px"></asp:ListBox>
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="Timer2" EventName="Tick" />
                        </Triggers>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" Width="490px" Height="90px" TextMode="MultiLine"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><asp:Label ID="Label8"
                        runat="server" Text="Label"></asp:Label>  
                    <asp:Label ID="Label7" runat="server" Text="Label" Visible="False"></asp:Label>
                    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="Timer2" EventName="Tick" />
                        </Triggers>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td>
                     <asp:Button ID="Button1" runat="server" Text="发送" Width="90px" OnClick="Button1_Click" />
                      
                    <asp:Button ID="Button4" runat="server" Text="关闭对话框" Width="90px" OnClick="Button4_Click" />
                                <asp:Button ID="Button3"
                        runat="server" Text="打开消息记录" OnClick="Button3_Click" Width="90px" />   <asp:Button
                            ID="Button5" runat="server" Text="关闭消息记录" OnClick="Button5_Click" Width="90px" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:GridView ID="MSG_Record" runat="server" Height="400px" Width="490px" AllowPaging="True"
                        OnPageIndexChanging="MSG_Record_PageIndexChanging" Visible="False">
                        <Columns>
                            <asp:BoundField DataField="TIME" HeaderText="消息发送时间" ReadOnly="True" />
                            <asp:BoundField DataField="U_NAME" HeaderText="消息发送者" ReadOnly="True" />
                            <asp:BoundField DataField="FRIEND_NAME" HeaderText="消息接收者" ReadOnly="True" />
                            <asp:BoundField DataField="MESSAGE_CONTENT" HeaderText="消息内容" ReadOnly="True" />
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </div>
    </form>


sendmsg.aspx.cs:


public partial class SendMSG : System.Web.UI.Page
{
    private static int last_ID;
    private static int lid1;
    //private DataSet dt;
    private string u_id;
    private string friend_id;
    private string u_name1;
    private string u_name2;
    private static string org_id;
    //private string userIP;
    //private HttpCookie cookie;
    /// <summary>
    /// 页面载入
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        //userIP = Request.UserHostAddress;
        //cookie = Request.Cookies["info+"+userIP+""];
        if (Request.QueryString["fid"] != null && Request.QueryString["fname"] != null)
        {
            friend_id = Request.QueryString["fid"].ToString();
            u_name2 = ImLoginBLL.getuser1(friend_id).REAL_NAME;
            Label8.Text = "与"+u_name2+"对话中!";           
            System.Web.HttpContext.Current.Session["FRIEND_ID_A"] = friend_id;
        }
        last_ID = GetLastID();
        if (!IsPostBack)
        {
            u_id = Session["U_ID"].ToString();//@@
            u_name1 = Session["REAL_NAME"].ToString();//@@

            //u_name1 = cookie.Values["u_name+" + userIP + ""];
            //u_id = cookie.Values["u_id+" + userIP + ""];
            org_id = Session["org_id"].ToString();
            Label2.Text = u_name1;
        }
        bind();
    }
    /// <summary>
    /// gridview 数据绑定
    /// </summary>
    protected void bind()
    {
        u_id = Session["U_ID"].ToString();//@@
        u_name1 = Session["REAL_NAME"].ToString();//@@
        MSG_Record.DataSource = SendMSG_BLL.GetListMessage(u_id, friend_id);
        MSG_Record.DataBind();
    }
    /// <summary>
    /// gridview 分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void MSG_Record_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        MSG_Record.PageIndex = e.NewPageIndex;
        bind();//分页时要重新绑定
    }
    /// <summary>
    /// 获取最新消息的ID
    /// </summary>
    /// <returns></returns>
    private int GetLastID()
    {
        try
        {
            u_id = Session["U_ID"].ToString();//@@
            u_name1 = Session["REAL_NAME"].ToString();//@@            
            //u_id = cookie.Values["u_id+" + userIP + ""];
            return last_ID= Convert.ToInt32(SendMSG_BLL.GetNewMessage(friend_id,u_id).MSG_ID);
        }
        catch
        {
            ListBox1.Items.Add("对不起,现在没有新消息!");//
            return -1;
        }
    }
    /// <summary>
    /// 发送消息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
        //u_id = cookie.Values["u_id+" + userIP + ""];
        //u_name1 = cookie.Values["u_name+" + userIP + ""];

        u_id = Session["U_ID"].ToString();//@@
        u_name1 = Session["REAL_NAME"].ToString();//@@

        if (TextBox1.Text == "")
        {
            Label7.Text = "对不起,不能发送空消息!请重新输入!";
            Label7.Visible = true;
        }
        else
        {
            Label7.Visible = false;
            IM_Model_MSG model = new IM_Model_MSG();
            
            model.TIME = DateTime.Now;
            model.MESSAGE_CONTENT = TextBox1.Text;
            model.IM_U_ID = u_id;
            model.U_NAME = u_name1;
            model.FRIEND_ID = friend_id;
            model.FRIEND_NAME = u_name2;
            model.ORG_ID = org_id;
            model.TRANS_DOC_RECOD = "";
            model.ISREAD = "0";

            string time = DateTime.Now.ToString();
            SendMSG_BLL.AddMessage(model);

            ListBox1.Items.Add(time + " " + model.U_NAME+":");
            string[] attr = model.MESSAGE_CONTENT.ToString().Split('\n');
            foreach (string i in attr)
            {
                ListBox1.Items.Add(i.ToString());
            }
            TextBox1.Text = "";
        }        
    }
    
    /// <summary>
    /// 判断是否有新消息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Timer2_Tick(object sender, EventArgs e)
    {
        //HttpCookie cookie = Request.Cookies["info"];
        //u_name1 = cookie.Values["u_name"];
        //u_id = cookie.Values["u_id"];
        last_ID = GetLastID();
        //dt = null;
        if ((lid1 < last_ID)&&(lid1!=-1)&&(last_ID!=-1))
        {
            //Timer1.Enabled = true;
            IM_Model_MSG model = new IM_Model_MSG();
            //u_id = cookie.Values["u_id+" + userIP + ""];
            //u_name1 = cookie.Values["u_name+" + userIP + ""];

            u_id = Session["U_ID"].ToString();//@@
            u_name1 = Session["REAL_NAME"].ToString();//@@

            model = SendMSG_BLL.GetNewMessage(friend_id, u_id);
            ListBox1.Items.Add(model.TIME + " " + model.U_NAME + ":");

            string[] attr = model.MESSAGE_CONTENT.ToString().Split('\n');
            foreach (string i in attr)
            {
                ListBox1.Items.Add(i.ToString());
            }
            lid1 = last_ID;
            SendMSG_BLL.msg_isread(lid1);
            
        }
        else
        {
            //ListBox1.Items.Add("对不起,现在没有新消息!");
            
        }
        Label3.Text = DateTime.Now.ToString();
    }
   
} --------------------编程问答-------------------- 备注:IE浏览器不好用;火狐浏览器好用
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,