首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

莫非是.net一BUG,该怎么解决

2012-03-14 
莫非是.net一BUGHTML code%@ Page TitleHome Page LanguageC# MasterPageFile~/Site.master Aut

莫非是.net一BUG

HTML code
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"    CodeFile="Default.aspx.cs" Inherits="_Default" %><asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content><asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">    <asp:DropDownList ID="DropDownList3" runat="server"  onselectedindexchanged="DropDownList3_SelectedIndexChanged">            <asp:ListItem>choose</asp:ListItem>        <asp:ListItem>delete</asp:ListItem>        <asp:ListItem>save</asp:ListItem>    </asp:DropDownList>    <br />    <br />    <br /><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></asp:Content>


C# code
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if (!Page.IsPostBack)        {            DropDownList3.Attributes.Add("onchange", "if(confirm(\'确认删除吗?\')){__doPostBack( ' " + DropDownList3.ClientID + " ', ' ');}else{return(false);} ");        }    }    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)    {        Label1.Text = "afasfasdfasdf";    }    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)    {        Random ran = new Random();        Label1.Text = "执行了后台事件" + ran.Next().ToString();    }}


上述代码可以执行dopostback事件

HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!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">    <div>        <br />    <br />    <br />    <asp:DropDownList ID="DropDownList3" runat="server"  onselectedindexchanged="DropDownList3_SelectedIndexChanged">            <asp:ListItem>choose</asp:ListItem>        <asp:ListItem>delete</asp:ListItem>        <asp:ListItem>save</asp:ListItem>    </asp:DropDownList>    <br />    <br />    <br /><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>    </div>    </form></body></html>


C# code
public partial class Default2 : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if (!Page.IsPostBack)        {            DropDownList3.Attributes.Add("onchange", "if(confirm(\'确认删除吗?\')){__doPostBack( ' " + DropDownList3.ClientID + " ', ' ');}else{return(false);} ");        }    }    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)    {        Label1.Text = "afasfasdfasdf";    }    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)    {        Random ran = new Random();        Label1.Text = "执行了后台事件" + ran.Next().ToString();    }} 


运行时 提示 Microsoft JScript runtime error: '__doPostBack' is undefined

莫非这是一BUG?

[解决办法]
占位
查看页面源码 不一样
[解决办法]
[size=13px][/size]我汗public partial class _Default : System.Web.UI.Page[size=14px][/size][i和public partial class Default2 : System.Web.UI.Page
[解决办法]
什么啊这是,不明白。你的__doPostBack方法在哪里写的?第二个都没看到这个方法在哪里,第一个难道是因为引用了母版页,母版页中有__doPostBack方法才能成功?我猜就是因为MasterPageFile="~/Site.master"中有__doPostBack方法。
[解决办法]
dopastback
是.NET 的服务器控件产生的。 所以要使用此函数,必须整个页面上至少要有一个控件 可以回传页面。有些控件 的autoPostBack 必须设为TRUE。

so this problem is solve. thanks, everyone

热点排行