我有点惊讶的是,在学习WPF/XAML/Silverlight时,我遇到的几乎所有XAML/C#示例都在XAML中有"Click"事件,在Window或Page构造函数中很少.
由于现在所有的重点都放在"非侵入式Javascript"上,我认为更多的开发人员实际上会像这样构建他们的XAML /代码隐藏:
XAML:
<Grid>
<Button x:Name="btnEdit"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
代码背后:
public Window1()
{
InitializeComponent();
btnEdit.Content = "Edit";
btnEdit.Click += new RoutedEventHandler(btnEdit_Click);
}
private void btnEdit_Click(object sender, RoutedEventArgs e)
{
btnEdit.Content = "This button was clicked.";
}
Run Code Online (Sandbox Code Playgroud)
有关为什么这会是一个好的或坏的做法的任何想法?
我有一个CreateUserWizard控件,正在执行服务器端验证.有没有办法强制从代码隐藏显示CUW的错误消息?此时,如果用户输入重复的名称,则会显示控件DuplicateUserNameErrorMessage属性.但是,如果用户关闭了javascript,或发送了带有无效字符的自定义POST标头,我依靠我的服务器端验证来捕获错误.然后,我如何在控件的ErrorMessage标签中显示相同的错误消息,而不是创建自定义标签并伪造它?
编辑:只是为了澄清,服务器端验证测试各个方面.重复用户只是控件调用ErrorMessage标签的示例.
谢谢
我猜是常见的问题,但到目前为止还没有解决办法:
我的断点(asp.net 2.0)在"后端"程序集中得到很好的打击但在后面的代码中却没有.
我甚至可以看到<%Response.CacheControl ="no-cache"; %>在我的asp.net主文件中被击中,但仍然不是后面的代码.
我正在使用VS 2005,Windows 7 32位.知道我还能检查什么吗?
这个问题说明了一切......非常简单,可以通过选择文件并按F7来完成,但我总是意外地双击,而visual studio需要永远打开设计视图页面(即使它几乎是空的) ,但我只是想直接去代码.
有小费吗?
configuration default code-behind visual-studio-2010 visual-studio
好的,所以我一直在寻找一个anwser,但我开始怀疑,如果我看到它,我是否会知道它.我是WPF的新手,但几年来一直在C#中使用Windows Forms.
我的问题是:为什么我不能从我"拖放"到网格后面的代码中访问标签并重命名?
XML代码:
<Window x:Class="IMCommand.NewProblemWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="New Problem" Height="800" Width="800" Loaded="Window_Loaded">
<Grid>
<GroupBox Header="Initial Detection and Recording" Height="168" HorizontalAlignment="Left" Margin="12,45,0,0" Name="groupBox1" VerticalAlignment="Top" Width="754" FontSize="15">
<Grid>
<Label Content="Application/Server" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label1" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="144,11,0,0" Name="textBox1" VerticalAlignment="Top" Width="324" Background="#FFCBCBCB"></TextBox>
<Label Content="AE Problem Ticket #" Height="28" HorizontalAlignment="Left" Margin="6,52,0,0" Name="label2" VerticalAlignment="Top" />
<TextBox Background="#FFCBCBCB" Height="23" HorizontalAlignment="Left" Margin="155,54,0,0" Name="BOX_AEProblem" VerticalAlignment="Top" Width="175" />
<Label Content="Start Time" Height="28" HorizontalAlignment="Left" Margin="6,86,0,0" Name="label4" VerticalAlignment="Top" Width="85" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="97,91,0,0" Name="BOX_StartTime" VerticalAlignment="Top" …Run Code Online (Sandbox Code Playgroud) 我的.aspx文件中包含以下代码
<ext:GridPanel
runat="server"
ID="GridPanel1"
Height="450"
Title="EmployeeList"
Width = "850"
Header = "false"
StyleSpec = "margin: 25px;"
StripeRows="true"
TrackMouseOver="true"
Border="true" ClicksToEdit="2">
<Store>
<ext:Store ID="Store1" runat="server" DataSourceID="LinqDataSource1">
<Reader>
<ext:JsonReader IDProperty="id" >
<Fields>
<ext:RecordField Name="id" />
<ext:RecordField Name="shortcode" />
<ext:RecordField Name="lastname" />
<ext:RecordField Name="firstname" />
<ext:RecordField Name="roomnumber" />
<ext:RecordField Name="landline" />
<ext:RecordField Name="mobile" />
<ext:RecordField Name="mail" />
<ext:RecordField Name="position" />
<ext:RecordField Name="department" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server" >
<Columns>
<ext:Column DataIndex="id" Header="Index" Width="50"/>
<ext:Column DataIndex="shortcode" Header="Kuerzel" Align="Center" />
<ext:Column …Run Code Online (Sandbox Code Playgroud) 我想隐藏使用C#的"li"标签的html列表项.但我不能这样做.在早些时候我只是使用c#隐藏DIV标签.但我无法隐藏"li"标签.请帮我这样做.如果可以,请发送您的详细说明......
这是我的部分代码:
this.hide.style.Add("display", "none"); // Error in hide
Run Code Online (Sandbox Code Playgroud)
这是我的HTML代码:
<li ID="hide" style="display: Block;"><a href="../list.aspx" >list Approval</a></li>
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题....
我正在为programmaticaly页面添加标签(codebehind file c#)
Label label1 = new Label();
label1.Text = "abc";
this.Page.Form.FindControl("ContentPlaceHolder1").Controls.Add(label1);
Label label2 = new Label();
label2.Text = "def";
this.Page.Form.FindControl("ContentPlaceHolder1").Controls.Add(label2);
Run Code Online (Sandbox Code Playgroud)
我想在这些标签之间添加hr和br.怎么做?
this.Page.Form.FindControl("ContentPlaceHolder1").Controls.Add("<hr/>");
Run Code Online (Sandbox Code Playgroud)
不起作用.
我是一名学生,使用MVVM模式学习使用WPF的C#.最近我一直致力于[我的应用程序的艺术(自定义启动画面),当我不希望它时,不应该关闭它.我一直在网上寻找一个没有代码隐藏的好方法.不幸的是,几天后我仍然没有找到令人满意的方式.然后我开始想到一种方法,在我的视图的构造函数中只有一行代码的帮助.它仍然使我的代码可测试并将代码与View分离.问题是,有没有更好的方法来做我想做的事情:
我的ViewModel界面
public interface IPreventCloseViewModel
{
bool PreventClose { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
View的扩展名
public static class PreventCloseViewModelExtension
{
/// <summary>
/// Use this extension method in the constructor of the view.
/// </summary>
/// <param name="element"></param>
public static void PreventCloseViewModel(this Window element)
{
var dataContext = element.DataContext as IDisposable;
if (dataContext is IPreventCloseViewModel)
{
element.Closing += delegate(object sender, CancelEventArgs args)
{
if (dataContext is IPreventCloseViewModel)
{
args.Cancel = (dataContext as IPreventCloseViewModel).PreventClose;
}
};
}
}
}
Run Code Online (Sandbox Code Playgroud)
View的代码隐藏
public partial …Run Code Online (Sandbox Code Playgroud) 我见过类似的问题,但没有一个答案帮助我解决了这个问题.我有一个带有ReadOnly字段的GridView,如下所示.
网格视图:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="projectID"
DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display."
PageSize="5" OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"/>
<asp:BoundField DataField="prID" HeaderText="prID" SortExpression="prID"/>
<asp:BoundField DataField="projectName" HeaderText="projectName"
SortExpression="projectName" />
<asp:BoundField DataField="projectType" HeaderText="projectType"
SortExpression="projectType" />
</Columns>
<EditRowStyle CssClass="GridViewEditRow"/>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,prIDBoundField具有Readonly=True属性.prID当用户更新行中的其他字段时,我正试图获取代码隐藏的值.
后台代码:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
String d1 = ((TextBox)(row.Cells[2].Controls[0])).Text;
String d2 = ((TextBox)(row.Cells[3].Controls[0])).Text;
// this only works while the field is not readonly
string prIDUpdate = …Run Code Online (Sandbox Code Playgroud)