Web Component design, using interface (IPostBackDataHandler) to generate data postback problems

Source: Internet
Author: User
Tags empty
web| Design | data | Problem 1. Component Source file IPostTest.cs

1using System;
2using System.Web.UI;
3using System.Web.UI.WebControls;
4using System.ComponentModel;
5
6namespace Mywebcontrol
7{
8///<summary>
9///iposttest Summary description.
Ten///</summary>
One [Defaultproperty ("Text"),
ToolBoxData ("<{0}:iposttest runat=server></{0}:iposttest>")]
public class Iposttest:system.web.ui.webcontrols.webcontrol,ipostbackdatahandler
14 {
private string user;
private string pwd;
17
18//Control name setting
private String UserName
20 {
Get
22 {
return this. UniqueID + ": User";
24}
25}
26
The private string Pwdname
28 {
Get
30 {
return this. UniqueID + ":p wd";
32}
33}
34
35//Public properties
The public string Uservalue
37 {
Get
39 {
return user;
41}
42}
43
The public string Pwdvalue
45 {
Get
47 {
PWD return;
49}
50}
51
///<summary>
53///renders this control to the specified output parameter.
///</summary>
///<param name= "Output" > the HTML writer you want to write </param>
protected override void Render (HtmlTextWriter output)
57 {
//output. AddAttribute (htmltextwriterattribute.name,this. UniqueID);
Output. RenderBeginTag (htmltextwritertag.table);
Output. RenderBeginTag (htmltextwritertag.tr);
Output. RenderBeginTag (HTMLTEXTWRITERTAG.TD);
62
Output. AddAttribute (Htmltextwriterattribute.name,username);
Output. AddAttribute (htmltextwriterattribute.value, (user = null)? String.Empty:user));
Output. AddAttribute (Htmltextwriterattribute.type, "text");
The output. RenderBeginTag (Htmltextwritertag.input);
Output. RenderEndTag ();//input
68
In output. AddAttribute (htmltextwriterattribute.name,this. UniqueID);
Output. AddAttribute (Htmltextwriterattribute.type, "hidden");
Output. AddAttribute (Htmltextwriterattribute.value, "DD");
The output of a. RenderBeginTag (Htmltextwritertag.input);
Output. RenderEndTag ();//input hidden
74
Output. RenderBeginTag (htmltextwritertag.br);
The output. RenderEndTag ();//br
77
to output. AddAttribute (Htmltextwriterattribute.name,pwdname);
Output. AddAttribute (Htmltextwriterattribute.value, (pwd = null)? STRING.EMPTY:PWD));
Output. AddAttribute (Htmltextwriterattribute.type, "text");
Bayi output. RenderBeginTag (Htmltextwritertag.input);
to output. RenderEndTag ();//input
83
Output. RenderEndTag ();//td
Output. RenderEndTag ();//tr
Output. RenderEndTag ();//table
87}
IPostBackDataHandler//Members
89
ipostbackdatahandler.raisepostdatachangedevent void ()
91 {
I//TODO: Add iposttest.raisepostdatachangedevent implementation
93}
94
ipostbackdatahandler.loadpostdata bool (string postdatakey, System.Collections.Specialized.NameValueCollection Values
96 {
I//TODO: Add Iposttest.loadpostdata implementation
The user = Values[username];
PWD = Values[pwdname];
return false;
101}
102
103}
104}
105
2. The test method adds the component to the custom control toolbar, drags it into the test page, adds a button control, and 3. Concludes that when multiple input child controls exist within a component, a child control must have the name of this. UniqueID to get the value of the other child controls to return. A. When I try to load a this.uniqueid onto a table, I can't get the value of its child control input. B. The above type is hidden input, you can cancel, but you must load the This.uniqueid onto any other control, otherwise you cannot get its value. I add a hidden type of input, purely for the sake of the corresponding, there is no other purpose. C. I really do not know much about Web controls, step by step, I do not know if you have encountered such a problem. Hope that the master can be a guide to thank you!

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.