各位大侠:谢谢了!请帮帮忙呀,万分感谢!小弟通过点击按钮,来生成一个表格,要判断,如下代码,如果条件成立生成表格,不成立,弹出对话框,但是希望如果不成立生成对话框时不要刷新之前的页面,不知如何实现请高手指点。有说使用Page的RegisterStartupScript,但是我使用后出现RegisterStartupScript已过期。
又有说要在前台判断,小弟菜鸟,不知道前台如何判断,代码写在前台哪里,请高手指点!
 protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Session["date"] = Convert.ToInt32(Session["date"]) - 10;
        if (Convert.ToInt32(Session["date"]) > 0)
        {
            -----创建一个表格
        }
        else
        {
            Response.Write("<script>alert('当前已是最后一页!')</script>");
            return;
        }    }

解决方案 »

  1.   

    已过期也没有说不能用,呵呵.只是说可以用
      Page.ClientScript.RegisterStartupScript
      

  2.   


    protected void LinkButton2_Click(object sender, EventArgs e) 
        { 
            Session["date"] = Convert.ToInt32(Session["date"]) - 10; 
            if (Convert.ToInt32(Session["date"]) > 0) 
            { 
                -----创建一个表格 
            } 
            else 
            { 
                this.LinkButton1.OnClientClick = "return alert('当前已是最后一页!')";
                return; 
            }     }
      

  3.   

    想不刷新界面,用asp.net ajax或者是其它方式实现ajax请求,比如jquery,js
      

  4.   

    你用服务器端的事件肯定要刷新的,除非用ajax
      

  5.   

    [Quote=引用 2 楼 amanizty 的回复:]
    谢谢兄弟了!你的方法可以实现,但是,弹出对话后,如果我点击确定还是会刷新,能不能点击确定,页面也不刷新呀!
      

  6.   

    一旦点击LinkButton2则引发LinkButton2_Click事件,不管你条件成立与否,都会刷新页面,服务器
    控件就是这样,没办法!所以现在只能在你点击button引发事件前判断!在button的onclientclick事件里写"return check();":
    function check()
    {
       var d = <%=Session["date"].ToString()%>;//直接传递你的session过来,如果传不过来
      //在cs里定义个protected的变量,把session的值得赋给此变量,这里用<%=变量%>就能传过来了
       if(d-10 > 0) return true;
       else return false;
    }
    button 
      

  7.   


    你用我下面的方法试下:
    function s()
        {
          var s=document.getElementById("TextBox1");
          var s2=document.getElementById("DropDownList1");
          var Error="";
          if(s.value=="")
          {
            Error+="姓名不允许为空!\r\n";
          }
          if(s2.options[s2.selectedIndex].value==0)
          {
            
            Error+="ddls不允许为空!\r\n";
          }
          if(Error!="")
          {
            alert(Error);
            return false;
          }
        }然后你在buuton按钮:
    <asp:Button ID="btnAdd" runat="server" Text="· 提交 ·" OnClientClick="return s();"  CommandName="Add" OnCommand="btn_Command" ></asp:Button>
      

  8.   


      Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('当前已是最后一页!')</script>");
      

  9.   

    我的方法有麻烦,就是用一个updatepanel仅仅把按钮包起来就是了<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="deleteWebApplication5._Default" %><!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>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
                </ContentTemplate>
            </asp:UpdatePanel>
            <%= DateTime.Now %>
        </div>
        </form>
    </body>
    </html>后台代码using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;namespace deleteWebApplication5
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {        }        protected void Button1_Click(object sender, EventArgs e)
            {
                ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, typeof(UpdatePanel), "alert", "alert('测试警告');", true);
                //ScriptManager.RegisterClientScriptBlock(this.Page, Page.GetType(), "alert", "alert('测试警告');", true);
            }
        }
    }