[Switch] The calendar operator controls the event handler of the generator and simulates _ dopostback () sending back.

Source: Internet
Author: User
Generally, calender adds sub-control lists as needed in dayrender events. If there is a requirement, add a worker in the daily memory cell of calender, and want to press this button to lead to the release of the click event, which generates a program related to the event.

The most direct method for the above requirements is to add a button to the cell and use addhandler to set the processing function of the click event. The Program program is as follows.

1 protected sub calendar1_dayrender (byval sender as object, byval e as system. Web. UI. webcontrols. dayrendereventargs)
Handles calendar1.dayrender
2 dim obutton as new button ()
3 obutton. Text = "divide"
4 addhandler obutton. Click, addressof button_click set the button click Handler
5 e. Cell. Controls. Add (obutton)
6 end sub
7
8 ''' <summary>
9 '''button click event handling function
10''' </Summary>
11 private sub button_click (byval sender as object, byval e as system. eventargs)
12' program used to compile button click
13 end sub

However, the response line above will be different from what you think. When a button produces a PostBack, it will not input the specified button_click method. Why? Because the subcontrol token generated during the calender dayrender event is not retained, you can view the calendar in the page load event. controls. count is equal to 0. The callback event control triggered by PostBack is based on the request. in form, the resource and control operator determines whether to trigger a correlated event, and the subcontrol operator does not exist at all, making it impossible to trigger its click event.

Another method can be used to determine the above problems, that is, to call _ dopostback () into _ eventtarget and _ eventargument data directly by calling _ dopostback () according to the sequence, then, the servo automatically handles the PostBack response.

Therefore, we use htmlbutton and call the _ dopostback () function directly in attributes ("onclick"). The _ eventtarget parameter is set to "calendardelete" as an exception, __eventargument specify the input date. During page load, use me. Request. Form ("_ eventtarget") to determine whether the value of the token should be based on the PostBack generated by the token and then redirect to the calendardelete method.

1 protected sub calendar1_dayrender (byval sender as object, byval e as system. Web. UI. webcontrols. dayrendereventargs)
Handles calendar1.dayrender
2 dim obutton as htmlbutton
3
4 obutton = new htmlbutton ()
5 obutton. innertext = "exclude"
6 obutton. attributes ("onclick") = "_ dopostback ('calendardelete', '" & E. Day. Date. tow.datestring ()&"');"
7 E. Cell. Controls. Add (obutton)
8 end sub
9
10 protected sub page_load (byval sender as object, byval e as system. eventargs) handles me. Load
11 if me. Request. Form ("_ eventtarget") = "calendardelete" then
12 dim odate as date
13 odate = date. parse (Me. Request. Form ("_ eventargument "))
14 calendardelete (odate)
15 end if
16
17 end sub
18
19 ''' <summary>
20''' calendar division by worker processing method.
21 ''' </Summary>
22 ''' <Param name = "value"> date. </Param>
23 private sub calendardelete (byval value as date)
24' create a program for Division
25 end sub

In the preceding method, if you write a token that the server controls, you can even modify the token in the calendar, and define events such as daydelete, dayupdate, or daycommand, it will be easier to use. In this way, the commandfield on the gridview will introduce the concept of a rowcommand event.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.