错误原因:  
     在页面上有几个linkbutton,每一个Linkbutton有一个后台事件,其中有一个是用来跳转到不同的页面
     当点击这个个Linkbutton后,出现错误,提示信息为”行:0错误:缺少对象“
     这时点击”调试“,会在VS2008中打开”windows script block"页面,上面只有一行代码为”__doPostBack('btnAdd','')。
尝试方法:
    在page_load中加入“this.ClientScript.GetPostBackEventReference(this, "");” 不行
将页面上一个控件的"autopostback"属性设为"true" 不行;在页面的<head>标签中加入一个<script type="text/javascript"> </script>也不行。
请问是什么原因造成linkbutton按钮失效的,如何解决,谢谢。

解决方案 »

  1.   

    你 不是用了 Response.Write 之类的?
      

  2.   

    protected void Page_Load(object sender, EventArgs e)
        {
            username = Session["username"] as string; 
            if (Session["UserPurview"] == null)
            {
                this.Response.Write("<script>top.location.href='../login.aspx';</script>");
            }
            else
            {
                UserPurview up = (UserPurview)Session["UserPurview"];
                if (up != null)
                {
                    bR = up.GetPageCanRead(")");
                    bI = up.GetPageCanInsert(")");
                    bD = up.GetPageCanDelete(")");
                    bU = up.GetPageCanUpdate(")");
                    bO = up.GetPageOtherLevel(")");
                }
            }        if (!this.IsPostBack)
            {
                if (this.Request["page"] != null)
                {
                    this.gvDepartments.PageIndex = Convert.ToInt32(this.Request["page"]);
                }
            }        this.lblErrMsg.Visible = false;
            this.GetPostBackEventReference(LinkButton3);   
        }
    按钮事件:
    protected void btnAdd_Click(object sender, EventArgs e)
        {
            string url = string.Format("DepartmentAdd.aspx?page={0}",
            this.gvDepartments.PageIndex);        this.Response.Redirect(url);
        }
    在page_load事件有Response.Write,有什么问题呢?
      

  3.   

    前台:
    <asp:LinkButton ID="btnAdd" runat="server" onclick="btnAdd_Click">增加</asp:LinkButton>
    后台:
    protected void btnAdd_Click(object sender, EventArgs e)
        {  
            string url = string.Format("DepartmentAdd.aspx?page={0}",
            this.gvDepartments.PageIndex);        this.Response.Redirect(url);
        }
      

  4.   

    肯定用AJAX。
    用另外一个框架就任何问题。
      

  5.   

    做了个实验:
    新建了一个ASPX页面。
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Base.aspx.cs" Inherits="BasicData1_Departments" %><!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>Untitled Page</title>
    </head>
    <body>
            <iframe id="department" scrolling="auto" frameborder="0" src="<%  Response.Write(pageUrl);%>" width="100%" height="100%"></iframe></body>
    </html>CS代码:
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;public partial class BasicData1_Departments : System.Web.UI.Page
    {
        public string pageUrl;
        protected void Page_Load(object sender, EventArgs e)
        {
            pageUrl = Request["page"];
        }
    }数据库里面:
    ~/BasicData1/Base.aspx?page=BasicData/Departments.aspx
    其他均不做改动。
    运行成功,没有报错。
    为什么这样不会报错呢???!!!
      

  6.   

    在 linkButton 中加上 target="_self"   <asp:LinkButton ID="LinkButton1" target="_self" runat="server">LinkButton</asp:LinkButton>