以编程方式创建asp:Button?

我正在使用我的代码隐藏页面以编程方式创建一个保存按钮: Button btnSave = new Button(); btnSave.ID = “btnSave”; btnSave.Text = “Save”; 但是我认为这必须创建一个html按钮或者可能需要其他东西,因为我似乎无法在下一行中设置OnClick属性,我可以指定OnClientClick,但这不是我想要设置的。

变量本身是否会占用内存?

当我们声明一个变量时,变量本身是否会消耗内存? class IHaveNothing { } class IHaveNullFields { string @string = null; StringBuilder @StringBuilder = null; } class Program { static void Main(string[] args) { IHaveNothing nothing = new IHaveNothing(); IHaveNullFields nullFields = new IHaveNullFields(); } } 实例nullFields比实例没有消耗更多的内存吗? 编辑:如果null局部变量而不是类’空字段,它们也消耗内存吗?

必须将带有’LinkBut​​ton’类型的控件xxx放在带有runat = server的表单标签内

我有一个DataGrid ,我试图在单击一个ASP.NET 按钮时导出。 确切的错误是: 必须将带有’LinkBut​​ton’类型的控件’ctl00_body_RollupDG_ctl02_btnShowGLdetail’放在带有runat = server的表单标记内。 我在这里发现了类似的问题,但似乎都表明这是因为ASP.NET控件没有放在ContentPlaceHolder中,或者ContentPlaceHolder 没有放在RunAt Server表单中。 我有这两个,所以情况并非如此。 我的ExportExcelFile方法捕获RenderControl()处的HttpException (如上面的屏幕截图所示)。 该代码如下: protected void ExportExcelFile(object Sender, EventArgs e) { //export to excel var grdResults = (periodCriteria.SelectedValue == “year”) ? RollupDG : QuarterDG; var response = HttpContext.Current.Response; response.Clear(); response.Charset = String.Empty; response.ContentType = “application/vnd.ms-excel”; response.AddHeader(“Content-Disposition”, “attachment; filename=GlBudgetReport.xls”); using (var sw = new StringWriter()) { […]

WebAPI上传错误。 MIME多部分流的预期结束。 MIME多部分消息未完成

作为MVC4的WebAPI的一部分,我一直在关注本教程以支持文件上传: http : //blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web -api.aspx 。 当我的控制器收到请求时,它会抱怨“MIME多部分消息未完成”。 有没有人有关于如何调试这个的任何提示? 我已经尝试将流的位置重置为0,因为在它遇到处理程序之前还有其他东西在读取它之前。 我的HTML看起来像这样: Select file(s) to upload : 和我的控制器的Post方法如下: public Task<IEnumerable> Post() { if (Request.Content.IsMimeMultipartContent()) { Stream reqStream = Request.Content.ReadAsStreamAsync().Result; if (reqStream.CanSeek) { reqStream.Position = 0; } string fullPath = HttpContext.Current.Server.MapPath(“~/App_Data”); var streamProvider = new MultipartFormDataStreamProvider(fullPath); var task = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception); […]

为什么C#编译器不能从函数签名推断generics类委托?

我正在使用一个函数,它将两个函数作为参数,并返回一个新的组合函数: public static Action Compose(Action first, Action second) { return new Action(arg => { first(arg); second(); }); } 我注意到编译器抱怨如果我没有指定T ,当发送静态或成员函数时(而不是实际的Action对象): static void Main(string[] args) { // compiler error here var composed = Compose(Test, () => Console.WriteLine(” world”)); composed(“hello”); Console.ReadLine(); } public static void Test(string arg) { Console.Write(arg); } 错误消息: 无法从用法中推断出方法’ConsoleTest.Program.Compose(System.Action,System.Action)’的参数。 尝试显式指定类型参数。 我的问题 :为什么不能在这里推断出类型论证? Test的签名在编译时是已知的,不是吗? 是否真的有一些function可以代替Test […]

为什么模型绑定器需要一个空构造函数

我需要一些基本面的帮助…… 我有这个控制器,用一个类的实例来提供我的视图(至少我认为它是如何工作的)。 所以,既然我给了我的视图一个新的对象实例,为什么它必须为我的post创建一个更新的模型绑定? 请看下面的例子。 [HttpGet] public ActionResult Index(){ int hi = 5; string temp = “yo”; MyModel foo = new MyModel(hi, temp); return View(foo); } [HttpPost] public ActionResult Index(MyModel foo){ MyModel poo = foo; if(poo.someString == laaaa) return RedirctToAction(“End”, “EndCntrl”, poo); else throw new Exception(); } View: @model myApp.models.MyModel @html.EditorFor(m => m.hi) Model: public class […]

在任何按钮中单击的事件(C#窗体)

我正在开发一个程序,它有许多按钮,点击时应该执行类似的操作,但根据点击的按钮有很小的差异。 问题是唯一直接的路径是为每个按钮编写代码,这将是一个非常重复的任务。 有没有办法只编程一个块,可以点击任何按钮,单击哪个按钮?

什么是用于连接和声明事件的C#代码的VB.NET等价物?

我正在开发一个在Silverlight中构建媒体播放器的教程 ,我正在尝试将EventHandler到DispatchTimer对象的timer.Tick事件,以便video的时间与Slider对象同步。 示例代码在C#中,我不能在我的生活中找出VB.NET中使用RaiseEvent和/或Handles连接事件的正确语法。 以下是相关的C#代码。 我会在我遇到困境的地方加上评论。 private DispatchTimer timer; public Page() { //… timer = new DispatchTimer(); timer.Interval = TimeSpan.FromMilliseconds(50); timer.Tick += new EventHandler(timer_Tick); // 0) { sliderScrubber.Value = VideoElement.Position.TotalSeconds / VideoElement.NaturalDuration.TimeSpan.TotalSeconds; } }

XSD:使用Visual Studio xsd.exe不生成Array 而不是List

我使用xsd.exe工具从xsd文件生成类。 xsd文件: 输出是: /// [System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”, “4.0.30319.1”)] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute(“code”)] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)] [System.Xml.Serialization.XmlRootAttribute(Namespace=””, IsNullable=false)] public partial class BAXML { private string counterpartyOrgNrField; private BAXMLLimit[] limitField; /// [System.Xml.Serialization.XmlElementAttribute(“Limit”)] public BAXMLLimit[] Limit { get { return this.limitField; } set { this.limitField = value; } }} /// [System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”, “4.0.30319.1”)] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute(“code”)] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)] public partial class BAXMLLimit { private string […]

有没有办法使用FileHelpers库进行字段顺序?

我从nuget下载了FileHelpers,但我不确定这个function是否不存在,或者我没有正确的版本或什么。 我一直在环顾四周 ,似乎FileHelpers可能有一个属性来指定字段顺序。 我下载了这个,但是当我在寻找nuget时,似乎还有另一个版本