My opinion on the problem of KW

Source: Internet
Author: User
Tags implement
Questions, these questions, they're pretty interesting.
I can't swim, just a few of the questions I know.
Give your opinion.

* Question 4. Talk about AutoEventWireup.
The Uestc95:autoeventwireup property is used to control whether the page framework is allowed to automatically invoke
Page_Init and Page_Load methods are, by default, True. "

My note: In page this directive vs will automatically help you write autoeventwireup= "false",
Remove it, the system defaults to True, it is the end of what it is, Uestc95 's answer is completely correct

We can do an experiment, set it to true, and then add a line of code to the Page_Load.
Response.Write ("I love you,babe!");
Then execute, haha, I have loved you two times.

Let's change something and put the sentence in InitializeComponent ()
This. Load + = new System.EventHandler (this. Page_Load); commented on
Do it again, haha, the disgusting words once again can.

The answer here is very clear, with the autoeventwireup= "true", we do not need to be in the event for page
Explicit binding processing method, the system will automatically execute Page_Init and Page_Load

* Question x: Extension question: How to dynamically, use a program (programmatically) to refer to a user control?
Do you have anything to be aware of?
It is well known that user control can be added to the page by adding tags in the HTML code
It can also be loaded dynamically in a program
The method is simple, first declare a mycontrol
protected System.Web.UI.Control mycontrol;

And then this
Mycontrol=loadcontrol ("Xxxxxxx.ascx");

and add it to a WebControl that inherits from System.Web.UI.Control, like panel.
MYPANEL.CONTROLS.ADD (mycontrol);

What if I want to manipulate my user control?
((Your user control's class name) mycontrol). The method you want to implement;

* Question 14: If you write a Custom control by inheriting System.Web.UI.Control,
How do I add support for client-side script?
"Uestc95: For example, to add a client script event in a <asp:button>:
BUTTON1.ATTRIBUTES.ADD ("onclick", "alert (' JAVASCRITP script for Client ')");

At first I thought it was for user control to add Client-side script support, look carefully, I read the wrong:-(
Uestc95 's answer was absolutely right, and it was worth worshipping him.

But there is one place where the problem is not quite right, it should be:
"If you write a Custom control by inheriting System.Web.UI.WebControls.WebControl,
Because only WebControl have this webcontrol.attributes property yo!

And, incidentally, if you want to implement a DataGrid-like in your user control,
Client-side JavaScript for Custom postback make sure your user control is implemented
System.Web.UI.IPostBackEventHandler this interface and then use Page.GetPostBackEventReference to teleport
Event parameters, and then use RaisePostBackEvent to get the parameter processing submission.
This has a complete example in QuickStart, and interested friends can go and see

* Question 16: How do you support Template by writing a control?
Can you write code in control to read the value of the content (such as controls) that will be put in the template?

This question is very strange, the experts who did not give the answer (because too easy:-), let us these divers are anxious to break
I'll try to answer it.

User control can support template, if it supports, we can give it a nickname: Templated control
First, templated control should implement INamingContainer to prevent controls placed in template and the names of the outside.
Please note that I have used the word should, instead of having to

Second, templated control must have at least one such attribute
The attribute type is itemplate and must have [TemplateContainer (typeof (the stuff in the template)] before the property read and write method.
The procedure is this:

Private ITemplate myTemplate = null;

[TemplateContainer (typeof in the template)]
Public ITemplate MyTemplate {
get {
return myTemplate;
}
set {
MyTemplate = value;
}
}

And then we're going to override the CreateChildControls method, like this:

protected override void CreateChildControls () {

if (myTemplate!= null) {
In the template into the dongdong i = new template into the Dongdong;
Mytemplate.instantiatein (i);
This. Controls.Add (i);
}
}

Writing here I found a problem, is this "the template put in the Dongdong" is my new out of the
Instead of parsing the ASPX code read, the side effect is that I've identified the contents of the template in advance.
This is not flexible, and may also contradict the original intention of the problem.
If anyone knows, hope to come out and solve the confusion!!!!!

The second question, I want to use FindControl this method should be able to handle it.



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.