我有一个带有名为'required'的Css类的文本框.当用户单击一个按钮时,我想在文本框中添加额外的Css类,称为"错误",而不删除"必需"类.我想从代码隐藏中实现这一点.
这是一个Visual Studio问题.我觉得所有有用的Intellisense应该有一些帮助,但我似乎无法找到它.
我在VS2008中使用ASP.NET C#编写了一个带有代码隐藏的页面,当然它会自动生成一个PageLoad事件方法.好吧,如果我想为PageLoad之外的更多事件添加方法怎么办?我想在Foo.aspx页面上会有一些列表可以添加可能的方法事件处理程序.是不是更像是PageInit,PageDispose,(或者等价)等......?我在哪里可以找到这些?
编辑 - 我当然可以在api中查找方法名称.我正在寻找一个方便的快捷方式在Visual Studio中添加这些.如果它生成一个,它不能成为其他人吗?
asp.net events code-behind event-handling visual-studio-2008
我在.ASCX文件的顶部有以下定义:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ArticleView.aspx.cs" Inherits="MyNameSpace.ArticleView" %>
Run Code Online (Sandbox Code Playgroud)
在该控件中,我使用<%=%>块来引用我在代码隐藏文件中声明的成员.如果我编译和部署控件,它工作正常.但是在Visual Studio中我遇到了很多设计时错误,"当前上下文中不存在"{some variable}." 而Intellisense也会中断:它适用于UserControl的成员,但找不到我自己声明的成员.还有其他问题.一般来说,一切都指向生成的ASP.articleview_ascx类以某种方式不从MyNameSpace.ArticleView类继承.
我发现如果我将CodeBehind属性切换为"CodeFile":
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ArticleView.aspx.cs" Inherits="MyNameSpace.ArticleView" %>
Run Code Online (Sandbox Code Playgroud)
突然Intellisense工作,所有的设计时错误都消失了.但我不想进行运行时编译,也不想部署我的.ASCX.CS文件 - 所以我不能使用CodeFile.
我检查简单的东西,比如确保我隐藏文件名是正确的和继承类有正确的命名空间,等等(而且由于它改变了属性的CodeFile后正常工作,这些必须是在正确的地方指指点点. ...)但我错过了什么?为什么它不能处理CodeBehind属性?
谢谢,
史蒂夫
更新:从下面的一个帖子 - 基本问题是,为什么不使用CodeFile?答:当我尝试在我的文件中使用CodeFile =进行部署时,在部署之后,我收到以下堆栈跟踪(完整呈现):
/_layouts/Pages/ViewPage.aspx.cs'不存在.在在System.Web.UI.TemplateParser.ProcessCodeFile(VirtualPath codeFileVirtualPath)在System.Web.UI.TemplateParser.ProcessMainDirectiveAttribute(字符串DEVICENAME,字符串名,字符串值,IDictionary的parseData System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath) )
(这是来自于/_layouts/Pages/ViewPage.aspx请求的ViewPage的是,有几个其他控件,包括在我原来的例子中提到的ArticleView页面这恰好是失败的第一个文件. - 如果我回去代码隐藏= IN的ViewPage,遂把ASCX用的CodeFile =会以同样的方式失败.)这似乎是页面编译器抱怨,因为继承的代码隐藏类无法在任何加载的DLL被发现,因此,预计必须有一个CS文件来进行按需编译.
这里的问题是我不想部署CS文件,只需要ASPX/ASCX.阅读了很多这样伟大的文章,我知道各种新的部署模式,虽然我从来没有使用任何东西,只有一个Web应用程序项目(从VS2003转发,我们是2005年的后期采用者和WAP模型已经已经被我们从2003年)在许多VS2005/8个项目交换了加时,我从来没有遇到过的问题与代码隐藏=,直到这个问题的智能感知出现了......虽然它并不能帮助,在这种情况下,我正在部署到SharePoint,这引入了全新的复杂性.
由于我之前没有使用CodeFile进行部署,因此我很可能在构建时错过了我应该在VS中设置的一些选项,以便强制进行预编译.我只需要像今天一样部署一组带有单个代码隐藏DLL的ASPX/ASCX.今天在CodeBehind = ...它正在使用最初提到的Intellisense问题,这正是我想要解决的问题:)
当我确定哪些文件可能与问题相关时,会发布更多内容...
asp.net intellisense code-behind visual-studio-2008 visual-studio
我通过IDictionary将Datagrid绑定到动态数据:http://www.scottlogic.co.uk/blog/colin/2009/04/binding-a-silverlight-datagrid-to-dynamic-data-via-idictionary/comment -page-1 /#评论- 8681
但我不想在xaml中定义任何列(下面是如何在Colin Eberhardt的帖子中完成它
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="Forename" Binding="{Binding Converter={StaticResource RowIndexConverter}, ConverterParameter=Forename}" />
</data:DataGrid.Columns>
Run Code Online (Sandbox Code Playgroud)
所以我编写了以下代码来尝试在后面的代码中执行相同的操作,但代码不会调用RowIndexConverter.必须遗漏一些东西.
码:
// add columns
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "Forename";
Binding bind = new Binding("Forename");
bind.Converter = new RowIndexConverter() ;
bind.ConverterParameter = "Forename";
textColumn.Binding = bind;
_dataGrid.Columns.Add(textColumn);
Run Code Online (Sandbox Code Playgroud)
其余代码(此处为上下文):
// generate some dummy data
Random rand = new Random();
for (int i = 0; i < 200; i++)
{
Row row = new Row();
row["Forename"] = s_names[rand.Next(s_names.Length)];
row["Surname"] = s_surnames[rand.Next(s_surnames.Length)]; …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习ASP.NET.根据我的理解,ASP.NET与旧式ASP的不同之处在于,页面的逻辑代码存在于单独的文件中,而不是嵌入在ASP页面中.因此,当用户请求像ShoppingCart.aspx这样的页面时,服务器会在顶部读取指令...
<%@ Page Title="" Language="C#" MasterPageFile="~/Styles/Site.Master" AutoEventWireup="true"
CodeBehind="MyShoppingCart.aspx.cs" Inherits="TailspinSpyWorks.MyShoppingCart" %>
这告诉服务器文件中的哪个文件和哪个类与页面相关联.类后面的代码还具有与页面上的每个控件相对应的成员变量,并为代码隐藏文件中的代码提供了一种操作控件的方法.
首先,我是否正确理解这一点?
其次,一个站点是否可以设置两个具有相同命名控件的独立ASPX页面,这两个页面都有一个指向同一文件和类的指令?你想要这样做吗?两个页面可以具有相同的功能,但具有不同的布局.我认为这可能是一种创建单独的"桌面"和"移动"版本的页面的方法,而不会在代码隐藏文件中复制内容.
我想最终我想知道的是,是否有办法定义一个抽象页面?假设创建一个抽象页面定义,说明页面必须有控件"cart_list","total_lbl",但是然后能够有多个页面继承自这个抽象页面?
你如何得到一个字符串的大小?在Windows Forms中,它很简单,我只使用图形对象然后使用MeasureString函数.在ASP.NET中我不知道如何做到这一点.
如何从代码后面调用javascript函数?
最受欢迎的回答是" ScriptManager.RegisterStartupScript",但这在我的情况下不起作用.
我有一个vb类正在进行数据库检查以查看是否存在记录.如果存在,则调用javascript函数以显示警报("Record exists")
所以我正在做类似的事情
Dim strMessage as string = "javascript:RecordExists('Param');"
Run Code Online (Sandbox Code Playgroud)
如何从我的vb.net类调用此函数?
我在FormView控件中有一个复选框和一个面板,我需要从后面的代码中访问它们,以便使用复选框来确定面板是否可见.这是我最初使用的代码,但由于我将控件放在FormView中,它不再有效.
Protected Sub checkGenEd_CheckedChanged(ByVal sender As Object, _
ByVal e As System.EventArgs)
If checkGenEd.Checked = True Then
panelOutcome.Visible = True
Else
panelOutcome.Visible = False
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
我已经开始根据我在这里查看的其他问题来解决这个问题,但是所有问题都是在C#而不是VB中,所以这就是我所得到的:
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If FormView1.CurrentMode = FormViewMode.Edit Then
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
所以,是的,我不确定如何完成它.对不起,这可能是非常基本的,但我是新来的,任何帮助都将不胜感激!
编辑:这是我现在的代码:
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If FormView1.CurrentMode = FormViewMode.Edit Then
CheckBox checkGenEd = formview1.FindControl("checkGenEd");
Panel panelOutcome = formview1.FindControl("panelOutcome");
End If
End …Run Code Online (Sandbox Code Playgroud) 我在我的ABC.ASPX页面上拖放一个Label控件.它正确编译.但是,Label2在代码隐藏ABC.ASPX.cs中,control()不可用于值赋值.
分辨率是多少?
<%@ Page language="c#" CodeBehind="ABC.aspx.cs" AutoEventWireup="false" %>
<asp:Label ID="Label2" runat="server" Font-Bold="True"></asp:Label>
Run Code Online (Sandbox Code Playgroud) 在我的页面中,我有一个CheckBoxList控件,我有7个项目.我想在我的Page_load代码生成中设置这7个项目.
我的页面:
<asp:CheckBoxList ID="WeeklyCondition" runat="server">
<asp:ListItem Value="1">Sat</asp:ListItem>
<asp:ListItem Value="2">Sun</asp:ListItem>
<asp:ListItem Value="3">Mon</asp:ListItem>
<asp:ListItem Value="4">Tue</asp:ListItem>
<asp:ListItem Value="5">Wed</asp:ListItem>
<asp:ListItem Value="6">Thu</asp:ListItem>
<asp:ListItem Value="7">Fri</asp:ListItem>
</asp:CheckBoxList>
Run Code Online (Sandbox Code Playgroud) code-behind ×10
asp.net ×9
.net ×3
c# ×3
vb.net ×2
checkboxlist ×1
controls ×1
converter ×1
css ×1
events ×1
formview ×1
intellisense ×1
javascript ×1
silverlight ×1
string ×1
webforms ×1
wpf ×1