custom-server-controls

Custom server control: specifying event declaratively on ASPX code

[亡魂溺海] 提交于 2019-12-11 07:35:29
问题 I'm currently working on several custom ASPX server controls. Of course these controls do also expose events. Now one possibility is to register a handler in the code, more specifically in the page where the custom server control resides...like protected void Page_Load(object sender, EventArgs e) { myCustomControl.Click += new .... } But how do I have to expose the event in my server control code s.t. I can declare these event handlers directly on the ASPX code (from the Property Editor),

Dynamically add CalendarExtender to Textbox subclass server control?

心不动则不痛 提交于 2019-12-11 03:48:32
问题 I'm trying to create a server control, which inherits from TextBox, that will automatically have a CalendarExtender attached to it. Is it possible to do this, or does my new control need to inherit from CompositeControl instead? I've tried the former, but I'm not clear during which part of the control lifecycle I should create the new instance of the CalendarExtender, and what controls collection I should add it to. I don't seem to be able to add it to the Page or Form's controls collection,

Generic ServerControl syntax?

核能气质少年 提交于 2019-12-10 15:22:32
问题 Is there a way that I can have a server control MyControl<T> so that I can register and use it in an aspx page like so <mc:MyControl<ThingForControlToUse> ID="instanceOfMyControl" runat="server" Obviously the designer doesn't like this, are there any cool ways round it other than creating a non generic wrapper with a type parameter? 回答1: Generic Tag Names are not possible in ASP.NET, please refer to this article: Generic Controls You are on the right track in thinking that you will need to

How do I enable ViewState for child custom controls when disabled in parent?

左心房为你撑大大i 提交于 2019-12-10 14:07:42
问题 I am trying to create a custom control that a "gridview" like control but specifcally for business objects that implement certain custom interfaces. In doing this I have come across the following problem. I have a control that I have disabled viewstate on (and I don't want to re-enable it) and it has a child control that I want viewstate enabled on. I can't seem to get the viewstate on the child control to work since its parents is disabled. Does anyone have any ideas of how to get that to

ASP.NET Server Control - How to add AssemblyInfo file

风格不统一 提交于 2019-12-10 02:39:12
问题 I've noticed on a few tutorials online that when a new ASP.NET Server Control is added, it automatically includes Properties folder (containing AssemblyInfo.cs) and a References folder. This works fine for me when creating a C# Server Control, but in VB.NET I just get a template .vb file and a Project file. Why is this and how can I get an AssemblyInfo.vb file? 回答1: AssemblyInfo.vb file is created for every project. By default it is not displayed in the Solution/Project Explorer. To view this

inherit from asp:validationsummary

浪子不回头ぞ 提交于 2019-12-09 23:05:51
问题 i have the requirement to show a nicely formatted error-message on top of the page (or control). therefore i implemented the render method of a new created server control. the new created control inherits from ValidationSummary. public class AgValidationSummary : ValidationSummary { protected override void Render(System.Web.UI.HtmlTextWriter writer) { if(this.Enabled) { if (Page.IsPostBack && !Page.IsValid) { my problem is now, that if an button is fired and his property CausesValidation is

send <style> info from custom server asp element

 ̄綄美尐妖づ 提交于 2019-12-08 02:47:34
问题 I want send to output CSS info in style blocks protected override void RenderContents(HtmlTextWriter output) { ... output.Write("<style> .... "); } But this block cant be nested in div block .I must place it in head.How can I do it or is there another approach? 回答1: The this.Page.Header.Stylesheet.CreateStyleRule method lets you add styles to the <head> . However, the CSS attributes that you can specify are limited to those supported by the Style class. (You can derive your own class from

Render Self-Closing Tag in ASP.NET custom control derived from Control

淺唱寂寞╮ 提交于 2019-12-07 07:10:25
问题 I'm working on a Facebook FBML controls library and would like to create my FBML controls somewhat patterned like the ASP.NET WebControls library. I have a base class that handles rendering by default; here's my render method: protected override void Render(HtmlTextWriter writer) { AddAttributesToRender(writer); if (UseXfbmlSemantics) { writer.RenderBeginTag(ElementName); writer.EndRender(); writer.RenderEndTag(); } else { writer.RenderBeginTag(ElementName); writer.RenderEndTag(); } } What I

Custom TextBox with built-in Validator: server side validation not firing

六月ゝ 毕业季﹏ 提交于 2019-12-06 16:16:56
问题 I have a class that looks like this: public class TextField : TextBox { public bool Required { get; set; } RequiredFieldValidator _validator; protected override void CreateChildControls() { base.CreateChildControls(); _validator = new RequiredFieldValidator(); _validator.ControlToValidate = this.ID; if(Required) Controls.Add(_validator); } public override void Render(HtmlTextWriter tw) { base.Render(tw); if(Required) _validator.RenderControl(tw); } } This has been working for a while in a

send <style> info from custom server asp element

安稳与你 提交于 2019-12-06 13:16:08
I want send to output CSS info in style blocks protected override void RenderContents(HtmlTextWriter output) { ... output.Write("<style> .... "); } But this block cant be nested in div block .I must place it in head.How can I do it or is there another approach? The this.Page.Header.Stylesheet.CreateStyleRule method lets you add styles to the <head> . However, the CSS attributes that you can specify are limited to those supported by the Style class. (You can derive your own class from Style if you need additional attributes.) C# example: protected override void OnPreRender(EventArgs e) { base