简体   繁体   English

C#Asp.Net用户控制按钮单击

[英]C# Asp.Net User Control button click

In my code I load a user control (uc) in the page_load event. 在我的代码中,我在page_load事件中加载了一个用户控件(uc)。 The uc contains a button which sets a label text to the textbox value. uc包含一个按钮,用于将标签文本设置为文本框值。 ( lblTest.Text = txtText.Text ) . lblTest.Text = txtText.Text )。 This works fine in the load event of my page. 这在我的页面的加载事件中工作正常。 But when I set the loading of the uc in my Init event, the label isn't set. 但是当我在我的Init事件中设置uc的加载时,标签没有设置。 When I set breakpoints, I see the button event is fired, the text is set (in the code), but when the page is finished loading, the label is empty. 当我设置断点时,我看到按钮事件被触发,文本被设置(在代码中),但是当页面加载完毕后,标签为空。 How is that possible? 怎么可能?

Check further down in the code to ensure that the control's text isn't being overwritten or set back to empty text. 在代码中进一步检查以确保控件的文本没有被覆盖或设置回空文本。 (Specifically, look further in Page_Init, functions that Page_Init invokes, and Page_Load and its invoked functions.) (具体来说,请进一步查看Page_Init,Page_Init调用的函数,以及Page_Load及其调用的函数。)

If you're seeing that it's being set in the debugger to the value that you expect, then chances are pretty good that something else is changing it after the fact. 如果你看到它在调试器中被设置为你期望的值,那么事后很可能还有其他东西在改变它。 That's going to be either your code, ViewState, or something else outside of your immediate control. 这将是您的代码,ViewState或其他您无法立即控制的内容。 Find that, and you should be able to do something about it. 找到它,你应该能够做些什么。

I dont think the control fully exists at init. 我不认为控件完全存在于init。

This article explains the page event cycle and may explain the issue you have: http://www.15seconds.com/issue/020102.htm 本文解释了页面事件周期,并可能解释您遇到的问题: http//www.15seconds.com/issue/020102.htm

To further elaborate a bit on the other answers. 进一步详细说明其他答案。

Whenever an ASP.Net site launches, five things happen in a very specific order . 每当ASP.Net站点启动时,就会以非常特定的顺序发生五件事。 Read Luke's link to find out that order and plot accordingly. 阅读Luke的链接,找出该订单并相应地进行绘图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.net c#按钮点击 - ASP.net c# button click 用户控件中的ASP.Net按钮的单击事件处理程序不起作用 - Click Event Handler of ASP.Net Button in User Control is not Working 在ASP.Net C#中,在按钮单击事件上,我在DataList中找到FileUpload控件,并且显示错误? - In ASP.Net C#, on button click event I find the FileUpload Control within DataList and It gives error? 以编程方式将控件添加到ASP.NET C#页面上的按钮单击 - Programatically Add Control to ASP.NET C# Page on Button Click 如何在按钮单击事件中的中继器中找到控件,并将中继器放置在ASP.NET C#的gridview中 - How to find control with in repeater on button click event and repeater is placed with in gridview in asp.net C# C#ASP.NET用户控件如何处理div点击服务器端? - C# ASP.NET User control How to handle a div click server side? 如果用户单击按钮,则使用c#通过asp.net在数据库中创建数据库表,怎么办? - if the user click on button then the database table is created in database through asp.net with c#,how can do? ModalPopUp作为用户控件ASP.NET C# - ModalPopUp as User Control ASP.NET C# 用户控件属性C#asp.net - User control properties C# asp.net 使用用户控件的ASP.NET C#下拉列表 - ASP.NET C# Dropdown List using User Control
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM