473,748 Members | 2,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

repost: custom control client values gone with postback -- no solution found...

Nobody knows how to get the values provided in the client can be read in the
user-control?
If have made a Web Custom Control with 2 textboxes and 1 dropdownlist.
The user fills in my control (the textboxes and the dropdownlist) and lots
more stuff on the page.
When the user wants to save the page he'll click the save button.
The server gets the postback but I can read out the filled in controls (in
my control).
The textboxes text = "" and the dropdown.select edindex = -1.
What do I forget/do wrong....many thanks in advance!!!
VS2005 Beta:

//Class wich containts the user controls:

using System;
using System.Collecti ons.Generic;

using System.Componen tModel;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Drawing;

namespace cusControls

{

[ToolboxBitmap(t ypeof(TextBox))]

[DefaultProperty ("Text")]

[ToolboxData("<{ 0}:TextBox runat=server></{0}:TextBox>")]

public class Textbox : TextBox

{

public enum TextBoxStyle

{

Text = 0,

Numeric = 1

}

[Bindable(true)]

[Category("Behav ior")]

public TextBoxStyle StyleMode

{

get

{

if (ViewState["cusMode"] == null)

return TextBoxStyle.Te xt;

else

return (TextBoxStyle)V iewState["cusMode"];

}

set

{

ViewState["cusMode"] = value;

}

}

protected override void OnPreRender(Eve ntArgs e)

{

if (StyleMode == TextBoxStyle.Nu meric)

{

if (!this.Page.Cli entScript.IsCli entScriptBlockR egistered(

"ValidateNumeri cScript"))

this.Page.Clien tScript.Registe rClientScriptBl ock(typeof(stri ng),

"ValidateNumeri cScript",

"<script language=javasc ript>" +

"function ValidateNumeric (){" +

"var keyCode = window.event.ke yCode;" +

"if (keyCode > 57 || keyCode < 48)" +

"window.event.r eturnValue = false;}" +

"</script>");

Attributes.Add( "onKeyPress ", "ValidateNumeri c()");

}

base.OnPreRende r(e);

}

public override string Text

{

get { return (base.Text); }

set

{

if (StyleMode == TextBoxStyle.Nu meric)

{

try

{

base.Text = Convert.ToInt32 (value).ToStrin g();

}

catch { };

}

else

{

base.Text = value;

}

}

}

}

[Designer(typeof (DatePickerDesi gner))]

[ToolboxBitmap(t ypeof(Calendar) )]

[ToolboxData("<{ 0}:DatePicker runat=server></{0}:DatePicker> ")]

public class DatePicker : WebControl

{

public enum FormatStyle

{

DMY = 0,

YMD = 1,

MDY = 2

}

[Bindable(true)]

[Category("Appea rance")]

public FormatStyle Format

{

get

{

if (ViewState["cusFormat"] == null)

return FormatStyle.DMY ;

else

return (FormatStyle)Vi ewState["cusFormat"];

}

set

{

ViewState["cusFormat"] = value;

}

}

public string SelectedDate

{

get

{

// How to retrieve the values of the Textboxes txtDay and txtYear and the
selected index of the dropdowlist ddlMonth?

//Controls[x] will get an nullreference.. ..Controls.Coun t gives 0 controls
back after postback.

}

set

{

//Not really needed cos the client provides these values(???)

}

}

protected override void CreateChildCont rols()

{

Textbox txtDay = new Textbox();

DropDownList ddlMonths = new DropDownList();

Textbox txtYear = new Textbox();

txtDay.StyleMod e = Textbox.TextBox Style.Numeric;

txtDay.MaxLengt h = 2;

txtDay.Width = 15;

ddlMonths.Items .Add("January") ;

ddlMonths.Items .Add("February" );

ddlMonths.Items .Add("March");

ddlMonths.Items .Add("April");

ddlMonths.Items .Add("May");

ddlMonths.Items .Add("Jun");

ddlMonths.Items .Add("July");

ddlMonths.Items .Add("August");

ddlMonths.Items .Add("September ");

ddlMonths.Items .Add("October") ;

ddlMonths.Items .Add("November" );

ddlMonths.Items .Add("December" );

ddlMonths.Selec tedIndex = (DateTime.Now.M onth) - 1;

txtYear.StyleMo de = Textbox.TextBox Style.Numeric;

txtYear.Width = 30;

switch (Format)

{

case FormatStyle.MDY :

Controls.Add(dd lMonths);

Controls.Add(tx tDay);

Controls.Add(tx tYear);

break;

case FormatStyle.YMD :

Controls.Add(tx tYear);

Controls.Add(dd lMonths);

Controls.Add(tx tDay);

break;

default:

case FormatStyle.DMY :

Controls.Add(tx tDay);

Controls.Add(dd lMonths);

Controls.Add(tx tYear);

break;

}

}

}

}

//Second class the designer:

using System;

using System.IO;

using System.Web;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Web.UI.D esign;

namespace cusControls

{

public class DatePickerDesig ner : System.Web.UI.D esign.ControlDe signer

{

public override string GetDesignTimeHt ml()

{

try

{

DatePicker ctl = (DatePicker)Com ponent;

StringWriter sw = new StringWriter();

HtmlTextWriter tw = new HtmlTextWriter( sw);

TextBox txtDay = new TextBox();

txtDay.Width = 15;

DropDownList ddl = new DropDownList();

ddl.Items.Add(" January");

ddl.Width = ctl.Width;

TextBox txtYear = new TextBox();

txtYear.Width = 30;

switch (ctl.Format)

{

case DatePicker.Form atStyle.MDY:

ddl.RenderContr ol(tw);

txtDay.RenderCo ntrol(tw);

txtYear.RenderC ontrol(tw);

break;

case DatePicker.Form atStyle.YMD:

txtYear.RenderC ontrol(tw);

txtDay.RenderCo ntrol(tw);

ddl.RenderContr ol(tw);

break;

default:

case DatePicker.Form atStyle.DMY:

txtDay.RenderCo ntrol(tw);

ddl.RenderContr ol(tw);

txtYear.RenderC ontrol(tw);

break;

}

return sw.ToString();

}

catch (Exception ex)

{

return ex.Message;

}

}

}

}


Nov 27 '05 #1
2 1697
I have found it myself.....
Problem solved.

"Pipo" <Pi**@home.co m> schreef in bericht
news:ur******** ******@TK2MSFTN GP14.phx.gbl...
Nobody knows how to get the values provided in the client can be read in
the user-control?
If have made a Web Custom Control with 2 textboxes and 1 dropdownlist.
The user fills in my control (the textboxes and the dropdownlist) and lots
more stuff on the page.
When the user wants to save the page he'll click the save button.
The server gets the postback but I can read out the filled in controls (in
my control).
The textboxes text = "" and the dropdown.select edindex = -1.
What do I forget/do wrong....many thanks in advance!!!
VS2005 Beta:

//Class wich containts the user controls:

using System;
using System.Collecti ons.Generic;

using System.Componen tModel;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Drawing;

namespace cusControls

{

[ToolboxBitmap(t ypeof(TextBox))]

[DefaultProperty ("Text")]

[ToolboxData("<{ 0}:TextBox runat=server></{0}:TextBox>")]

public class Textbox : TextBox

{

public enum TextBoxStyle

{

Text = 0,

Numeric = 1

}

[Bindable(true)]

[Category("Behav ior")]

public TextBoxStyle StyleMode

{

get

{

if (ViewState["cusMode"] == null)

return TextBoxStyle.Te xt;

else

return (TextBoxStyle)V iewState["cusMode"];

}

set

{

ViewState["cusMode"] = value;

}

}

protected override void OnPreRender(Eve ntArgs e)

{

if (StyleMode == TextBoxStyle.Nu meric)

{

if (!this.Page.Cli entScript.IsCli entScriptBlockR egistered(

"ValidateNumeri cScript"))

this.Page.Clien tScript.Registe rClientScriptBl ock(typeof(stri ng),

"ValidateNumeri cScript",

"<script language=javasc ript>" +

"function ValidateNumeric (){" +

"var keyCode = window.event.ke yCode;" +

"if (keyCode > 57 || keyCode < 48)" +

"window.event.r eturnValue = false;}" +

"</script>");

Attributes.Add( "onKeyPress ", "ValidateNumeri c()");

}

base.OnPreRende r(e);

}

public override string Text

{

get { return (base.Text); }

set

{

if (StyleMode == TextBoxStyle.Nu meric)

{

try

{

base.Text = Convert.ToInt32 (value).ToStrin g();

}

catch { };

}

else

{

base.Text = value;

}

}

}

}

[Designer(typeof (DatePickerDesi gner))]

[ToolboxBitmap(t ypeof(Calendar) )]

[ToolboxData("<{ 0}:DatePicker runat=server></{0}:DatePicker> ")]

public class DatePicker : WebControl

{

public enum FormatStyle

{

DMY = 0,

YMD = 1,

MDY = 2

}

[Bindable(true)]

[Category("Appea rance")]

public FormatStyle Format

{

get

{

if (ViewState["cusFormat"] == null)

return FormatStyle.DMY ;

else

return (FormatStyle)Vi ewState["cusFormat"];

}

set

{

ViewState["cusFormat"] = value;

}

}

public string SelectedDate

{

get

{

// How to retrieve the values of the Textboxes txtDay and txtYear and the
selected index of the dropdowlist ddlMonth?

//Controls[x] will get an nullreference.. ..Controls.Coun t gives 0 controls
back after postback.

}

set

{

//Not really needed cos the client provides these values(???)

}

}

protected override void CreateChildCont rols()

{

Textbox txtDay = new Textbox();

DropDownList ddlMonths = new DropDownList();

Textbox txtYear = new Textbox();

txtDay.StyleMod e = Textbox.TextBox Style.Numeric;

txtDay.MaxLengt h = 2;

txtDay.Width = 15;

ddlMonths.Items .Add("January") ;

ddlMonths.Items .Add("February" );

ddlMonths.Items .Add("March");

ddlMonths.Items .Add("April");

ddlMonths.Items .Add("May");

ddlMonths.Items .Add("Jun");

ddlMonths.Items .Add("July");

ddlMonths.Items .Add("August");

ddlMonths.Items .Add("September ");

ddlMonths.Items .Add("October") ;

ddlMonths.Items .Add("November" );

ddlMonths.Items .Add("December" );

ddlMonths.Selec tedIndex = (DateTime.Now.M onth) - 1;

txtYear.StyleMo de = Textbox.TextBox Style.Numeric;

txtYear.Width = 30;

switch (Format)

{

case FormatStyle.MDY :

Controls.Add(dd lMonths);

Controls.Add(tx tDay);

Controls.Add(tx tYear);

break;

case FormatStyle.YMD :

Controls.Add(tx tYear);

Controls.Add(dd lMonths);

Controls.Add(tx tDay);

break;

default:

case FormatStyle.DMY :

Controls.Add(tx tDay);

Controls.Add(dd lMonths);

Controls.Add(tx tYear);

break;

}

}

}

}

//Second class the designer:

using System;

using System.IO;

using System.Web;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Web.UI.D esign;

namespace cusControls

{

public class DatePickerDesig ner : System.Web.UI.D esign.ControlDe signer

{

public override string GetDesignTimeHt ml()

{

try

{

DatePicker ctl = (DatePicker)Com ponent;

StringWriter sw = new StringWriter();

HtmlTextWriter tw = new HtmlTextWriter( sw);

TextBox txtDay = new TextBox();

txtDay.Width = 15;

DropDownList ddl = new DropDownList();

ddl.Items.Add(" January");

ddl.Width = ctl.Width;

TextBox txtYear = new TextBox();

txtYear.Width = 30;

switch (ctl.Format)

{

case DatePicker.Form atStyle.MDY:

ddl.RenderContr ol(tw);

txtDay.RenderCo ntrol(tw);

txtYear.RenderC ontrol(tw);

break;

case DatePicker.Form atStyle.YMD:

txtYear.RenderC ontrol(tw);

txtDay.RenderCo ntrol(tw);

ddl.RenderContr ol(tw);

break;

default:

case DatePicker.Form atStyle.DMY:

txtDay.RenderCo ntrol(tw);

ddl.RenderContr ol(tw);

txtYear.RenderC ontrol(tw);

break;

}

return sw.ToString();

}

catch (Exception ex)

{

return ex.Message;

}

}

}

}

Nov 28 '05 #2
so share your knowlege.. :)
Dec 1 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3626
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
21
2100
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a string with comma delimited values. For example, if I were to render two text boxes. One with the Value Terry and the Other with the Value 'Burns' I would get the following value Terry,Burns.
1
1976
by: Lamont Adams | last post by:
Hi all, I've created numerous custom controls of varying complexity, but I've been on this problem for a day and a half, and I can't figure this mystery out. I hope one of you kind folks can point out the really obvious and stupid thing I'm overlooking here. :) I have a custom control that provides a tasklist similar to what you get in certain parts of Office. On the client it consists of a bunch of nested, named and id'ed divs with...
2
2594
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a good while and I'm getting really frustrated now! My problem is this - my custom controls periodically disappear from my
3
1164
by: Pipo | last post by:
Hi, I'm trying to make my own web custom control. I've made a control with 2 textboxes and 1 dropdownlist. But when I enter values in them and get a postback the values are gone. How can I hold the values typed in by the client?? (for processing on the server but also to display them back) tia
0
1335
by: Iain | last post by:
Can I apologise for the lengthy nature of this post. The scenario is complicated (though I hope the solution is not!) basically, I've got a custom template control which binds itself to a tree structure. The template items describe how each particular note type of the tree should be rendered (the nodes are data capture elements - bool string and more complicated things). I don't want to use ViewState because of size (there are...
3
3005
by: Beavis | last post by:
I hate to repost a message, but I am still at the same point where I was when I originally posted, and hopefully someone else will see this one... Ok, so I have gone off and documented the lifecycle of a page with a custom composite control on it. You can find that document here: http://www.ats-engineers.com/lifecycle.htm
3
2135
by: ThunderMusic | last post by:
Hi, I have a custom control that draws many thing on the screen including a hidden field. This hidden field's value is modified through client code. What I want to do is the following : When there is a postback of the page, I want this hidden field to keep it's value (from the viewstate or something like this). Is there an easy solution? Would you need the code. Right now I : create a HiddenField in the PreRender of my control store...
15
6520
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt accept other controls. The control i drag drop on it becomes the child of my custom control's parent form and not the child of my custom control. Then i added this line "" before my custom control class (i dont know what this line does). Now
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.