奇怪的问题!vs.net 常常会莫名其妙的修改Web Form Designer generated code

brightzh 2003-04-30 02:47:15
最近在做一个asp.net项目。用vs.net C#。

但是发觉vs.net经常莫名其妙的修改InitializeComponent()这个函数。比如说较早的时候,在页面上放了一个按钮,并在后端写了一些代码,可是过了几天后,这段代码不能执行了,跟踪发现就根本没有执行这段代码,后来才发现InitializeComponent()这个函数里面被修改了,vs.net好像自己删除掉了对应的事件处理程序。

这可是个大问题啊!不知道有什么解决方法
...全文
48 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ganz 2003-05-01
  • 打赏
  • 举报
回复
以前我也常运到这种问题。
修改某个控件的属性后,InitializeComponent()将会被自动清空。

写的东西多啦,才明白。

页面的布局绝对不能用ASP:TABLE。
包含在ASP:TABLE中的其它WEB控件由于无法自动生成事件的代码,所以你会去往InitializeComponent()手式添加这个事件。修改某个控件的属性后,InitializeComponent()将会被自动清空。
建议用TABLE代替ASP:TABLE

近期做过的几个项目都没有出现楼主所说的问题。
yigeyigeyige 2003-04-30
  • 打赏
  • 举报
回复
InitializeComponent中不宜添加用户代码,我看一些教材中也是这么说的。
brightzh 2003-04-30
  • 打赏
  • 举报
回复
哦。
原来大家都有这个苦恼!

To (Lostinet):
刚注意到高手的信誉不太好啊!95分。干了什么坏事!
imfine 2003-04-30
  • 打赏
  • 举报
回复
没办法,自己多注意
xiongliang2003 2003-04-30
  • 打赏
  • 举报
回复
呵呵,这个经常遇到,最容易丢失的就是 事件的了,多注意下关于事件的就可以了
luckysusan 2003-04-30
  • 打赏
  • 举报
回复

如果电脑慢,就别点那么快!
Lostinet 2003-04-30
  • 打赏
  • 举报
回复
是这样的啦。。
页面东西一多就容易出事。
希望2003版的没有这个BUG就好了。
brightzh 2003-04-30
  • 打赏
  • 举报
回复
但是原本没错的东西,他不应该删除阿。
我不可能检查每个页面,看看是否原先有的代码,现在不能运行了啊!
Meyer 2003-04-30
  • 打赏
  • 举报
回复
InitializeComponent()
就是由开发环境维护的。
Ajax实现无刷新三联动下拉框 1.html代码 Ajax实现无刷新三联动下拉框 <form id="Form1" method="post" runat="server">
省市
城市
市区
form> 2.cs代码 using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace AjaxTest { /**//// /// Summary description for WebForm1. /// public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.DropDownList DropDownList1; protected System.Web.UI.WebControls.DropDownList DropDownList2; protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.DropDownList DropDownList3; private void Page_Load(object sender, System.EventArgs e) { Ajax.Utility.RegisterTypeForAjax(typeof(AjaxMethod)); if(!Page.IsPostBack) { this.DropDownList1.DataSource=AjaxMethod.GetProvinceList(); this.DropDownList1.DataTextField="province"; this.DropDownList1.DataValueField="provinceID"; this.DropDownList1.DataBind(); this.DropDownList1.Attributes.Add("onclick","cityResult();"); this.DropDownList2.Attributes.Add("onclick","areaResult();"); } } Web Form Designer generated code#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /**//// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }3.AjaxMethod using System; using System.Data; using System.Data.SqlClient; namespace AjaxTest { /**//// /// Summary description for AjaxMethod. /// public class AjaxMethod { GetProvinceList#region GetProvinceList public static DataSet GetProvinceList() { string sql="select * from province"; return GetDataSet(sql); } #endregion GetCityList#region GetCityList [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)] public DataSet GetCityList(int provinceid) { string sql="select * from city where father="+provinceid; return GetDataSet(sql); } #endregion GetAreaList#region GetAreaList [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)] public DataSet GetAreaList(int cityid) { string sql="select * from area where father="+cityid; return GetDataSet(sql); } #endregion GetDataSet#region GetDataSet public static DataSet GetDataSet(string sql) { string ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]; SqlDataAdapter sda =new SqlDataAdapter(sql,ConnectionString); DataSet ds=new DataSet(); sda.Fill(ds); return ds; } #endregion } }4.web.config
每每听到客户抱怨自己修改和很久的数据由于自己的一个误操作而丢失时,总想让web页面也有像window窗体一样具有提示保存的功能。所以,经过一段时间的研究以后终于实现了这个功能!============ checksave.js =======================<script language="JScript">function window::onbeforeunload(){if (typeof(document.all[‘txtCheckFlag‘]) != "undefined") // to detect whether this page need prompt the save message!{ if (event.clientY<0 && event.clientX>document.body.clientWidth-20 || event.clientY<0 && event.clientX<20 || event.altKey || event.clientY>document.body.clientHeight) event.returnValue="If you have modified some data, you need push the save button to save them. Do you want to save?";}}forms(0).submit(); return false; }else // If does not need { window.location=arg; return true; }}function showsavemessage(arg){if (window.confirm("Save Change?")) { document.all["txtSave"].value="1"; document.forms(0).submit(); return false; }else { if (arg == ".") { return true; } else { window.location=arg; return false; } }}//-->Codebehind="test.aspx.vb" Inherits="Test.test" smartNavigation="True" %> test .NET 7.0" name="GENERATOR"> CODE_LANGUAGE"> vs_defaultClientScript"> vs_targetSchema"> <form id="Form1" method="post" runat="server"> sohu
yahoo
MTR LinkButton form> ======== test.aspx.vb ===============Public Class test Inherits System.Web.UI.Page Protected WithEvents txtSave As System.Web.UI.WebControls.TextBox Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents txtCheckFlag As System.Web.UI.WebControls.TextBox#Region " Web Form Designer Generated Code " ‘This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init ‘CODEGEN: This method call is required by the Web Form Designer ‘Do not modify it using the code editor. InitializeComponent() End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ‘Put user code to initialize the page here txtSave.Style.Item("display") = "none" txtCheckFlag.Style.Item("display") = "none" LinkButton1.Attributes("onclick") = "javascript:return checksave(this.href)" ‘ Page.RegisterStartupScript("Prompt", "<script language=""javascript"">function pageload() { } 0 Then Page.RegisterStartupScript("warning", "<script language=""javascript"">function pageload() {if (showsavemessage(‘.‘)) " + Session("URL") + ";}function pageload() {showsavemessage(‘" + Session("URL") + "‘);} 0 Then Session("URL") = Replace(txtCheckFlag.Text, "javascript:", "") Page.RegisterStartupScript("warning", "<script language=""javascript"">function pageload() {" + Session("URL") + ";} 0 Then Session("URL") = Replace(txtCheckFlag.Text, "javascript:", "") Page.RegisterStartupScript("Redirect", "<script language=""javascript"">function pageload() {" + Session("URL") + ";}function pageload() {window.location=‘" + Session("URL") + "‘;} 0 Then Page.RegisterStartupScript("TxtSave", "<script language=""javascript"">" + Session("URL") + " 0 Then Session("URL") = Replace(txtCheckFlag.Text, "javascript:", "") Page.RegisterStartupScript("TxtSave", "<script language=""javascript"">function pageload() {" + Session("URL") + ";}function pageload() {window.location=‘" + Session("URL") + "‘;}function pageload() {window.location=‘TestNoNeedCheck.aspx‘;}function pageload() {window.location=‘TestNoNeedCheck.aspx‘;}
WindowBuilder is a powerful and easy to use bi-directional Java GUI designer that makes it very easy to create Java GUI applications without spending a lot of time writing code to display simple forms. With WindowBuilder you can create complicated windows in minutes. Use the visual designer and Java code will be generated for you. You can easily add controls using drag-and-drop, add event handlers to your controls, change various properties of controls using a property editor, internationalize your app and much more. WindowBuilder is built as a plug-in to Eclipse and the various Eclipse-based IDEs (RAD, RSA, MyEclipse, JBuilder, etc.). The plug-in builds an abstract syntax tree (AST) to navigate the source code and uses GEF to display and manage the visual presentation. Using WYSIWYG layout tools, you don't need to write any lines of java code - the code will be generated for you by WindowBuilder. You can easily add any component to a container by using drag-and-drop, add an event handler to your controls, change various properties of controls using property editors and much more. Generated code doesn't require any additional custom libraries to compile and run: all of the generated code can be used without having WindowBuilder installed. WindowBuilder can read and write almost any format and reverse-engineer most hand-written Java GUI code. It also supports free form code editing (make changes anywhere...not just in special areas) and most user refactorings (you can move, rename and subdivide methods without a problem).

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧