无法在Visual Studio 2017(VB)中的Web窗体上创建事件处理程序 [英] Can't create an event handler on Web Form in Visual Studio 2017 (VB)

查看:140
本文介绍了无法在Visual Studio 2017(VB)中的Web窗体上创建事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我遵循的步骤:

文件 - >新项目

选定的ASP.NET Web应用程序(.NET Framework 4.6.1)

选定的空网站

然后,添加新的Web窗体并命名为Default.aspx

File --> New Project
Selected ASP.NET Web Application (.NET Framework 4.6.1)
Selected Empty Web Site
Then, Add New Web Form and named it Default.aspx

我现在可以向表单添加控件,然后双击按钮创建事件处理程序。 一切正常。 但是,在我关闭它并重新打开之后  (作为开放项目或开放网站) 我不能再双击控件
来创建事件处理程序。 我收到了消息: 无法完成操作。 

I can now add controls to the form and double click the button to create the event handler.  All works fine.  But, after I close it and re-open it  (either as Open Project or as Open Website)  I can no longer double click on a control to create the event handler.  I get the message:  Could not complete the action. 

此外,VB代码中的所有控件名称都用红色加下划线,我收到以下错误消息: 

In addition, all the control-names are underlined in red in the VB code and I get the following the error messages: 

严重级代码描述项目文件行抑制状态

错误BC30451未声明"Label1"。由于其保护级别,它可能无法访问。

Severity Code Description Project File Line Suppression State
Error BC30451 'Label1' is not declared. It may be inaccessible due to its protection level.

严重级代码描述项目文件行抑制状态

错误BC30506 Handles子句需要在包含类型中定义的WithEvents变量或者其基本类型之一。

Severity Code Description Project File Line Suppression State
Error BC30506 Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

它将运行但我无法通过双击控件创建事件处理程序,并且控件未列在代码隐藏屏幕的下拉框中。

It will run but I cannot create event handlers by double clicking on the control and the controls are not listed in the drop down box on the code behind screen.

以下是我为了向您显示错误而创建的简单网页示例。 我注意到page指令中的Inherits名称与VB中的class-name不同。 我在创建网页时做错了什么? 
我重新安装了Visual Studio 2017并仍然遇到同样的问题。 

Here is a sample of a simple web page I created to show you the errors.  I have noticed that the Inherits name in the page directive is different from the class-name in the VB.  Am I doing something wrong during the creation of my web pages?  I reinstalled Visual Studio 2017 and still have the same problem. 

Public Class _Default

Inherits System.Web.UI.Page

Public Class _Default
Inherits System.Web.UI.Page

受保护的子Button1_Click(发件人为对象,e为EventArgs)处理Button1.Click

Label1.Text =" Help!"

结束子



结束等级

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = "Help!"
End Sub

End Class

<%@ Page Language =" vb" AutoEventWireup = QUOT假QUOT;代码隐藏= QUOT; Default.aspx.vb"继承= QUOT; WebTest2._Default" %>

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebTest2._Default" %>

<!DOCTYPE html>

<!DOCTYPE html>

< html xmlns =" http://www.w3.org/1999/ xhtml">

< head runat =" server">

< title>< / title>

< / head>
$
< body>

< form id =" form1" runat =" server">

< div>

< / div>

< asp:Label ID =" label1的" RUNAT = QUOT;服务器" Text =" Label">< / asp:Label>

< br /> < br />

< asp:按钮ID =" Button1" RUNAT = QUOT;服务器"文本= QUOT;按钮和QUOT; />
$
< / form>

< / body>

< / html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br /> <br />
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>

推荐答案

您好SRC18,

Hi SRC18,

欢迎来到MSDN论坛。

Welcome to MSDN forum.

谢谢你的支持你提供的文件,我复制它们来替换我的代码,它在我身边很好用。但是当我对设计器文件进行一些更改时,会出现与下面相同的问题:

Thank you for the files you provided, i copy them to replace my code and it works well at my side. But when i do some changes in designer file, the same issue as you happened like below:

所以请检查Default.aspx.designer.vb中的代码,我想你的问题可能是与它有关。 

So please check the code in the Default.aspx.designer.vb, I think your issue may have something to do with it. 

建议:

1.点击Default.aspx,然后选择"显示所有文件"。如下所示:

1.Click Default.aspx and choose "show all files" like below:

2.然后我们可以找到Default.aspx.designer.vb文件,打开它并检查其中的控件ID。

2.Then we can find a Default.aspx.designer.vb file, open it and check the control ID in it.

要使VB的Web表单运行良好,Default.aspx中的控件misc(ID),Default.aspx.vb中的控件名称和控件ID in Default.aspx.designer.vb,这三个值必须相同。

To make web forms of VB work well, the misc(ID) of control from Default.aspx , the control Name in Default.aspx.vb and the control ID in Default.aspx.designer.vb , these three values must be the same.

3.重建项目,如果成功,请检查此问题是否仍然存在。

3.Rebuild the project and if succeed, check if this issue persists.

此外,如果您有一个可能导致此类问题的aspx文件副本,请查看

this

In addition, if you have a copy of aspx file which may cause such issue, have a look at this.

希望以上所有内容都可以帮助您解决问题问题。如果有效,请给我们反馈。

Hope all above can help solve your issue. And please give us a feedback if it works or not.

期待您的回复!

最好的问候

Lance


这篇关于无法在Visual Studio 2017(VB)中的Web窗体上创建事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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