Next, the last content. Next, let's keep moving its time. Create a new class tiptime3, create the script file tiptime3.js, set tiptime2CodeAll are copied.
In order to convert the datetime object of C # To the date of JS, We need to transmit the data to JS within milliseconds from midnight, January 1.
The rest of the work is to use setinterval to change the text of the span tag every one second, skipping.
The next step is to use ajax to obtain the server time. First, let the control implement the icallbackeventhandler interface.
This interface contains two methods. Raisecallbackevent is used to process parameters passed by the client. It is not required here, so it is empty. Getcallbackresult is used to process the data returned to the client,
Here, a random time is returned to make the effect obvious.
Note that you need to add this line to the onload method:
Page. clientscript. getcallbackeventreference (this ,"","","");
This is done to ensure that the webform_docallback method is generated on the page.
The rest is called by the client. The parameter descriptions of the webform_docallback method are as follows:
Uniqueid of the control to be called back
Callback Parameters
Client RESPONSE event after callback ends
Callback Context
Client RESPONSE event after callback Error
Asynchronous or not
Add an onclick event to the button and call the webform_docallback method. After the callback is complete, the result will be displayed on the span tag in the response event.
At this time, we found that if the page is returned, the widget's location will return to the original location, therefore, the location must be stored in the <input type = "hidden"/> label after each drag.
Create a class tiptime4, create the script file tiptime4.js, and copy the tiptime3 code.
Create two properties, X, and Y, to store the coordinates of the control on the client, and output an input tag in the rendercontents method to ensure that the coordinate information of the client still exists when it is returned.
Note that viewstate is not used for storing the attribute X and Y, because the two values exist in the form data, which is similar to the text attribute of the Textbox Control.
The name attribute must be set for the input label above, otherwise it will not be submitted along with the form.
In order to obtain the value of the input tag after the return, the control must implement the ipostbackdatahandler interface.
The loadpostdata method is used to check the data submitted to the server. It determines whether to call the raisepostdatachangedevent method based on the control status data and whether the returned data is changed,
If true is returned, the. NET Framework automatically calls the raisepostdatachangedevent method, which can trigger custom events.
Here, only the send-back data is stored in the X and Y attributes.
Next we need to add
Page. registerrequirespostback (this );
This is to ensure that the ipostbackdatahandler interface is triggered during callback.
Then, set the left and right attributes of the control in the addattributestorender method:
Finally, you can save the coordinates of the control to the input tag when dragging in Js.
The final function to be added is to automatically return and trigger a custom event. Create a tiptime class and a script file tiptime. js
Copy the tiptime4 code. Add an attribute to store the scheduled time of the Configuration:
Then define custom events. The above statements are fixed. In this way, you can see the event in the design view.
Then implement the ipostbackeventhandler Interface
When the condition is set, a custom event is executed.
The next step is to determine whether it is time in JS. If so, call the _ dopostback method to implement the callback and pass the uniqueid of the control as a parameter,
In this way, the server can know which control triggers the return event.
Note that you must add the following in the onload method:
Page. clientscript. getpostbackeventreference (New postbackoptions (this ));
In this way, the _ dopostback method is available on the page and the ipostbackeventhandler interface is triggered.
So far, all functions are implemented.
Download Sample Code
ASP. NET custom control development example (1)