Init事件不会触发 [英] Init event does not fire

查看:108
本文介绍了Init事件不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在这里遗漏一些东西:控件的Init事件似乎没有

开火。


我做了什么:

在空白的webform上放一个文本框,挂钩文本框的Init事件。

代码:

this.Textbox1.Value =" Hello World" ;;


文本框显示为空白,如果我在该行代码上设置断点,

我发现它永远不会触发。我在这里做错了什么?

I must be missing something here: The Init event for controls does not seem
to fire.

What I did:
Drop a textbox on a blank webform, hook the textbox''s Init event.
Code:
this.Textbox1.Value = "Hello World";

The textbox comes up blank, and if I set a breakpoint on that line of code,
I find that it never fires. What am I doing wrong here?

推荐答案




为了设置文本框值,你应该删除服务器内的那一行

旁边事件:


private void Page_Load(object sender,System.EventArgs e)

{

this.TextBox1.Text =" ff";

}


Natty Gur [MVP]


博客: http://weblogs.asp.net/ngur

手机:+ 972-(0)58-888377

***通过Developersdex发送 http://www.developersdex.com ***

不要只是参加USENET ......获得奖励!
Hi,

In order to set textbox value you should drop that line inside server
side event:

private void Page_Load(object sender, System.EventArgs e)
{
this.TextBox1.Text = "ff";
}

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


谢谢,我可以忍受。但我仍然很好奇。为什么

init事件无法触发?那个错误吗?我使用不正确吗?如果是这样,它打算如何使用?


" Natty Gur" < NA *** @ dao2com.com>在消息中写道

news:eZ ************** @ TK2MSFTNGP09.phx.gbl ...
Thanks, I can live with that. But I am still very curious. Why doesn''t the
init event fire? Is that bug? Was I using it incorrectly? If so, how is
it intended to be used?

"Natty Gur" <na***@dao2com.com> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...

为了设置文本框值,你应该在服务器边缘事件中删除该行:

private void Page_Load(object sender,System.EventArgs e)
{
this.TextBox1.Text =" ff";
}

Natty Gur [MVP]

博客: http://weblogs.asp.net/ngur
手机:+ 972-(0)58- 888377

***通过开发人员指南 http://www.developersdex.com发送 ***
不要只是参加USENET ......获得奖励!
Hi,

In order to set textbox value you should drop that line inside server
side event:

private void Page_Load(object sender, System.EventArgs e)
{
this.TextBox1.Text = "ff";
}

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!






我对此问题做了更多研究。这应该是我们产品的问题。 init事件在VB.NET中触发,但它不会在

C#.NET中触发。请在VB.NET中尝试以下简单代码。

------------------------------- ----------------

公共类WebForm1

继承System.Web.UI.Page


#Region" Web窗体设计器生成的代码


''Web窗体设计器需要此调用。

< System.Diagnostics.DebuggerStepThrough()> Private Sub

InitializeComponent()

End Sub

Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox


''注意:Web需要以下占位符声明

表单设计器。

''不要删除或移动它。

私人designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object,ByVal e As

System .EventArgs)处理MyBase.Init

''CODEGEN:Web表单设计器需要此方法调用

''不要使用代码编辑器修改它。 />
InitializeComponent()

结束子


#End Region


Private Sub Page_Load( ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load

''将用户代码置于此处初始化页面

End Sub


Private Sub TextBox1_Init(ByVal sender As Objec t,ByVal e As

System.EventArgs)处理TextBox1.Init

TextBox1.Text =" test inint"

End Sub

结束班

---------------------------------- -


我会将此问题报告给产品团队。非常感谢

提供这些重要信息。如果您对此问题有任何疑虑,请随时告诉我们。


祝你好运,


Jacob Yang

Microsoft在线合作伙伴支持

安全! - www.microsoft.com/security

发布是按原样提供的。没有保证,也没有赋予任何权利。

Hi,

I have done more research regarding this issue. It should be a problem of
our product. The init event fires in VB.NET but it does not fire in
C#..NET. Please try the following simple code in VB.NET.
-----------------------------------------------
Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

''This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox

''NOTE: The following placeholder declaration is required by the Web
Form Designer.
''Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

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
End Sub

Private Sub TextBox1_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Init
TextBox1.Text = "test inint"
End Sub
End Class
------------------------------------

I will report this issue to the product team. Thank you very much for
providing this important information. If there are any more concerns for
this issue, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


这篇关于Init事件不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆