In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use DateTimePicker, a custom control of ASP.NET source code. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
ASP.NET source custom control DateTimePicker introduction: written in front: to achieve DateTimePicker function, the simplest is an input, next to a calendar icon, add a lot of javascript code, and then, click on the calendar, there will be a div to select the date, selected, input will appear just selected date. And input should be read-only.
DateTimePicker effect of custom control for ASP.NET source code
Marking
Register Assembly= "DateTimePickerControls" Namespace= "DateTimePickerControls" TagPrefix= "DTP"
This is written on top of the aspx page and is used to reference dll's resources.
Attribute definitions corresponding to namespaces in the source code
[assembly: TagPrefix ("DateTimePickerControls", "DTP")]
Add to the toolbox
You can use the following method to add a custom ASP.NET control to the toolbox. If the control does not appear in the toolbox after the introduction of DLL, you can right-click in the toolbox, select the item, and then select DLL. The following ToolboxData represents the name of the control, and Designer represents what the control looks like in the design interface (DesignMode). Note that the DateTimePickerControls.DateTimePickerDesigner class must exist to show this sentence. DescriptionAttribute describes the role of the control.
[ToolboxData ("), ValidationPropertyAttribute (" Text "), Designer (typeof (DateTimePickerControls.DateTimePickerDesigner)), DescriptionAttribute (" an ASP.NET time selector based on MSHTML. ") ]
Inherit
Public class DateTimePicker: Control, IPostBackDataHandler, INamingContainer, IPostBackEventHandler
Control is the Control under the System.Web.UI space, representing the class of the Web control, while IPostBackDataHandler is the method that defines the ASP.NET server control that must be implemented to load postback data automatically. That is, use _ Control.Tex instead of Request.QueryString ["..."] . ToString () or Request.Form ["…"] .ToString (), to get the data in Html, the main methods are LoadPostData, RaisePostDataChangedEvent, while INamingContainer and IPostBackEventHandler are not used much for the time being. The author only refers to other Web controls and adds these two interfaces.
Registration script
Notice that each Web custom control has its own Javascript or Vbscript script, and when there are multiple such controls on the page. Do not apply multiple identical scripts appear.
So, use the Page.ClientScript.IsClientScriptBlockRegistered method to register the script. Such a registration script is equivalent to having a Hashtable to save the script, and each injected script has a Key associated with it. The advantage of this is that when using multiple scripts, they are not written repeatedly on the page.
The following code uses the script file written in the resource file, in other words, you can write the script file, such as the Javascript or Vbscript script, and then copy it directly to the
If (! Page.ClientScript.IsClientScriptBlockRegistered ("DateTimePickerBaseScript")) {ResourceManager manager = new ResourceManager (this.GetType ()); string script = manager.GetResourceSet (System.Globalization.CultureInfo.CurrentCulture, true, true) .GetString ("DateTimePickerBaseScript"); Page.ClientScript.RegisterClientScriptBlock (this.GetType (), "DateTimePickerBaseScript", script);}
The source code for the .resx file can look like this:
The advantage of writing a script in a resource file is obvious, that is, the contents of .js can be copied and pasted directly here without further processing.
Custom control of ASP.NET source code DateTimePicker overrides the method inherited by Control
Protected override void OnPreRender (EventArgs e)
Protected override void CreateChildControls ()
You can use the OnPreRender method as the OnLoad method of a normal Page, while the CreateChildControls method is used to create new child controls, which is the main code for constructing custom controls.
Get the Text property
Public bool LoadPostData (String postDataKey, NameValueCollection values) {string PresentValue = this.ViewStateText; string PostedValue = values [base.ID]; if (! PresentValue.Equals (PostedValue)) {this.Text = PostedValue; return true;} else {return false;}}
The above is to use the LoadPostData method to get the value of the Text property. Note that this method sometimes does not run, this is because your ChildControls does not have an ID = base.ID control, then there must be a child control ID for the ID of this control, the child control here does not refer to the controls under the System.Web.UI space, but refers to those controls that can be displayed in the client browser, that is, the use of string to express. Just like
Written in the WriteTimePicker method. "
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.