无法在后面的代码中访问控制 ID

Can#39;t access control ID in code behind(无法在后面的代码中访问控制 ID)
本文介绍了无法在后面的代码中访问控制 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 aspx 页面中有以下代码:

I have the following code in my aspx page:

 <asp:Button runat="server" ID="myButton" Text="hello" />

这在我后面的代码中:

protected void Page_Load(object sender, EventArgs e)
{ 
    myButton.Text = "bye"; 
}

由于某种原因,intellisense 会在后面的代码中获取myButton" id,但是当它编译时会显示

For some reason the intellisense picks up the "myButton" id in the code behind but when it compiles it says

它无法构建,因为它无法识别它!

it can't build because it doesn't recognise it!

我的页面是使用母版页的默认 aspx 页面,按钮位于内容控件内,并且所有设置为在服务器上正确运行,页面运行并显示正常,除了此按钮分辨率问题!

My page is a default aspx page which uses a master page, the button is inside a content control and all is set to run at server correctly, the page runs and displays fine except for this button resolution issue!

有什么想法吗?

推荐答案

听起来您的设计器文件 (PageName.designer.cs) 有点乱了.我会尝试从您的页面中删除该按钮并重新添加.

Sounds like your designer file (PageName.designer.cs) has got a bit messed up. I'd try deleting the button from your page and adding it again.

这篇关于无法在后面的代码中访问控制 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)