I got a problem when I try to extend a textbox.
So I overwrite the Render method. For the stuff I try to do, I would like
to add a custom attribute to my customized textbox.
So it renders something like this:
I modify the value of "myattribute" using javascript, but when I submit my
form, I can't get the value of "myattribute".
Do I have to create create a class extended the attribute class? How do I
have to proceed?
Thank you in advance,
Fabien.
Re: Extended control issue
am 26.12.2007 01:33:38 von Hal Rosser
"Fabien Henriet" wrote in message
news:e%23y8oo0RIHA.1188@TK2MSFTNGP04.phx.gbl...
> Hello,
>
> I got a problem when I try to extend a textbox.
> So I overwrite the Render method. For the stuff I try to do, I would like
> to add a custom attribute to my customized textbox.
> So it renders something like this:
>
>
> I modify the value of "myattribute" using javascript, but when I submit my
> form, I can't get the value of "myattribute".
>
> Do I have to create create a class extended the attribute class? How do I
> have to proceed?
>
> Thank you in advance,
> Fabien.
When you submit the form, each form element with a "name" attribute and a
"value" attribute will be sent as a 'pair' or 'set' of name=value pairs. For
example this element will
provide color=blue.
HTH
Re: Extended control issue
am 26.12.2007 10:23:29 von Fabien Henriet
Thank you for your quick answer!
I've already thought to use an hiddenfield. But I don't know how to get the
value of this field in my extended control.
I explain: when I submit my form, I call a method of my extended textbox and
within this method, I would like to test the value of my hiddenfield. I
prefer not to make that test in code behind of my page.
Thanks in advance for your help.
Fabien.
"Hal Rosser" a écrit dans le message de news:
fjhcj.30637$vt2.27658@bignews8.bellsouth.net...
>
> "Fabien Henriet" wrote in message
> news:e%23y8oo0RIHA.1188@TK2MSFTNGP04.phx.gbl...
>> Hello,
>>
>> I got a problem when I try to extend a textbox.
>> So I overwrite the Render method. For the stuff I try to do, I would
>> like to add a custom attribute to my customized textbox.
>> So it renders something like this:
>>
>>
>> I modify the value of "myattribute" using javascript, but when I submit
>> my form, I can't get the value of "myattribute".
>>
>> Do I have to create create a class extended the attribute class? How do
>> I have to proceed?
>>
>> Thank you in advance,
>> Fabien.
>
> When you submit the form, each form element with a "name" attribute and a
> "value" attribute will be sent as a 'pair' or 'set' of name=value pairs.
> For example this
> element will provide color=blue.
> HTH
>
Re: Extended control issue
am 26.12.2007 10:38:58 von l.holota
Hi,
it's simple, find the HiddenField in page (you can get the current page
instance by anyControl.Page), every control has a FindControl method (but it
searches only his childs not childs of his childs.....) so if the
hiddenField is somewhere deep, you will have use recursion to find the
control. Then you will get it's value by yourHiddenField.Value
Regards,
Lukas Holota
"Fabien Henriet" wrote in message
news:eRpxBE6RIHA.5360@TK2MSFTNGP03.phx.gbl...
> Thank you for your quick answer!
> I've already thought to use an hiddenfield. But I don't know how to get
> the value of this field in my extended control.
>
> I explain: when I submit my form, I call a method of my extended textbox
> and within this method, I would like to test the value of my hiddenfield.
> I prefer not to make that test in code behind of my page.
>
> Thanks in advance for your help.
>
> Fabien.
>
>
> "Hal Rosser" a écrit dans le message de news:
> fjhcj.30637$vt2.27658@bignews8.bellsouth.net...
>>
>> "Fabien Henriet" wrote in message
>> news:e%23y8oo0RIHA.1188@TK2MSFTNGP04.phx.gbl...
>>> Hello,
>>>
>>> I got a problem when I try to extend a textbox.
>>> So I overwrite the Render method. For the stuff I try to do, I would
>>> like to add a custom attribute to my customized textbox.
>>> So it renders something like this:
>>>
>>>
>>> I modify the value of "myattribute" using javascript, but when I submit
>>> my form, I can't get the value of "myattribute".
>>>
>>> Do I have to create create a class extended the attribute class? How do
>>> I have to proceed?
>>>
>>> Thank you in advance,
>>> Fabien.
>>
>> When you submit the form, each form element with a "name" attribute and a
>> "value" attribute will be sent as a 'pair' or 'set' of name=value pairs.
>> For example this
>> element will provide color=blue.
>> HTH
>>
>
>
Re: Extended control issue
am 26.12.2007 11:59:30 von Fabien Henriet
Hello,
Thank you but it doesn't work. I try in debug mode. In fact, I can find
the value of my hiddenfield by using
(this.Page.Request.Form.GetValues(base.ID + "_hidden"))[0], but the value is
not the good one. The value is the orignal one (before any modification in
javascript). I can't get the value modified by the javascript.
I cannot use FindControl because at this time, the object is not yet
"re-created" (after submit but before render).
Regards and thank you again,
Fabien.
a écrit dans le message de news:
86EB63DB-35C8-494E-BD4B-BD10203F1AF0@microsoft.com...
> Hi,
>
> it's simple, find the HiddenField in page (you can get the current page
> instance by anyControl.Page), every control has a FindControl method (but
> it searches only his childs not childs of his childs.....) so if the
> hiddenField is somewhere deep, you will have use recursion to find the
> control. Then you will get it's value by yourHiddenField.Value
>
> Regards,
>
> Lukas Holota
>
> "Fabien Henriet" wrote in message
> news:eRpxBE6RIHA.5360@TK2MSFTNGP03.phx.gbl...
>> Thank you for your quick answer!
>> I've already thought to use an hiddenfield. But I don't know how to get
>> the value of this field in my extended control.
>>
>> I explain: when I submit my form, I call a method of my extended textbox
>> and within this method, I would like to test the value of my hiddenfield.
>> I prefer not to make that test in code behind of my page.
>>
>> Thanks in advance for your help.
>>
>> Fabien.
>>
>>
>> "Hal Rosser" a écrit dans le message de news:
>> fjhcj.30637$vt2.27658@bignews8.bellsouth.net...
>>>
>>> "Fabien Henriet" wrote in message
>>> news:e%23y8oo0RIHA.1188@TK2MSFTNGP04.phx.gbl...
>>>> Hello,
>>>>
>>>> I got a problem when I try to extend a textbox.
>>>> So I overwrite the Render method. For the stuff I try to do, I would
>>>> like to add a custom attribute to my customized textbox.
>>>> So it renders something like this:
>>>>
>>>>
>>>> I modify the value of "myattribute" using javascript, but when I submit
>>>> my form, I can't get the value of "myattribute".
>>>>
>>>> Do I have to create create a class extended the attribute class? How
>>>> do I have to proceed?
>>>>
>>>> Thank you in advance,
>>>> Fabien.
>>>
>>> When you submit the form, each form element with a "name" attribute and
>>> a "value" attribute will be sent as a 'pair' or 'set' of name=value
>>> pairs. For example
>>> this element will provide color=blue.
>>> HTH
>>>
>>
>>
Re: Extended control issue
am 26.12.2007 14:48:43 von pjondevelopment
Hi, Fabien,
You're almost there with the solution, but instead of using base.ID
use this.ClientID.
This way you'll make sure that the property is retrieved no matter
where the control is placed.
It's always dificult to create custom properties on the client side...
One of the most terrifying aspects of it is the lack of
__defineGetter__ and __defineSetter__ in the Internet Explorer, which
I circunvent using behaviors (and __defineGetter__ and
__defineSetter__ for Gecko) it's ugly but it works.
So if you want your property to mork like, say, "value" you'll need to
type some more code. ;)
Let me know if you have questions
Paulo Santos
http://pjondevelopment.50webs.com
On Dec 26, 8:59=A0am, "Fabien Henriet" wrote:
> Hello,
>
> Thank you but it doesn't work. =A0I try in debug mode. =A0In fact, I can f=
ind
> the value of my hiddenfield by using
> (this.Page.Request.Form.GetValues(base.ID + "_hidden"))[0], but the value =
is
> not the good one. =A0The value is the orignal one (before any modification=
in
> javascript). =A0I can't get the value modified by the javascript.
> I cannot use FindControl because at this time, the object is not yet
> "re-created" (after submit but before render).
>
> Regards and thank you again,
> Fabien.
>
> a =E9crit dans le message de news:
> 86EB63DB-35C8-494E-BD4B-BD10203F1...@microsoft.com...
>
>
>
> > Hi,
>
> > =A0 =A0it's simple, find the HiddenField in page (you can get the curren=
t page
> > instance by anyControl.Page), every control has a FindControl method (bu=
t
> > it searches only his childs not childs of his childs.....) so if the
> > hiddenField is somewhere deep, you will have use recursion to find the
> > control. Then you will get it's value by yourHiddenField.Value
>
> > Regards,
>
> > Lukas Holota
>
> > "Fabien Henriet" wrote in message
> >news:eRpxBE6RIHA.5360@TK2MSFTNGP03.phx.gbl...
> >> Thank you for your quick answer!
> >> I've already thought to use an hiddenfield. =A0But I don't know how to =
get
> >> the value of this field in my extended control.
>
> >> I explain: when I submit my form, I call a method of my extended textbo=
x
> >> and within this method, I would like to test the value of my hiddenfiel=
d.
> >> I prefer not to make that test in code behind of my page.
>
> >> Thanks in advance for your help.
>
> >> Fabien.
>
> >> "Hal Rosser" a =E9crit dans le message de news=
:
> >> fjhcj.30637$vt2.27...@bignews8.bellsouth.net...
>
> >>> "Fabien Henriet" wrote in message
> >>>news:e%23y8oo0RIHA.1188@TK2MSFTNGP04.phx.gbl...
> >>>> Hello,
>
> >>>> I got a problem when I try to extend a textbox.
> >>>> So I overwrite the Render method. =A0For the stuff I try to do, I wou=
ld
> >>>> like to add a custom attribute to my customized textbox.
> >>>> So it renders something like this:
> >>>>
>
> >>>> I modify the value of "myattribute" using javascript, but when I subm=
it
> >>>> my form, I can't get the value of "myattribute".
>
> >>>> Do I have to create create a class extended the attribute class? =A0H=
ow
> >>>> do I have to proceed?
>
> >>>> Thank you in advance,
> >>>> Fabien.
>
> >>> When you submit the form, each form element with a "name" attribute an=
d
> >>> a "value" attribute will be sent as a 'pair' or 'set' of name=3Dvalue
> >>> pairs. For example
" />
> >>> this element will provide color=3Dblue.
> >>> HTH- Hide quoted text -
>
> - Show quoted text -
Re: Extended control issue
am 27.12.2007 09:00:24 von Fabien Henriet
Hello,
Thank you for your answer, but I'm not sure to understand the difference
between base.Id and this.ClientID... Both of those strings will return the
same value... I can get back the id or name of my hiddenfield, I can't get
back the value of this item assigned client-side.
Am I wrong?
Regards,
Fabien.
"PJ on Development" a écrit dans le message de
news: 1b12df87-0b70-40c6-b81d-323e4bf4953c@d21g2000prf.googlegroup s.com...
Hi, Fabien,
You're almost there with the solution, but instead of using base.ID
use this.ClientID.
This way you'll make sure that the property is retrieved no matter
where the control is placed.
It's always dificult to create custom properties on the client side...
One of the most terrifying aspects of it is the lack of
__defineGetter__ and __defineSetter__ in the Internet Explorer, which
I circunvent using behaviors (and __defineGetter__ and
__defineSetter__ for Gecko) it's ugly but it works.
So if you want your property to mork like, say, "value" you'll need to
type some more code. ;)
Let me know if you have questions
Paulo Santos
http://pjondevelopment.50webs.com
On Dec 26, 8:59 am, "Fabien Henriet" wrote:
> Hello,
>
> Thank you but it doesn't work. I try in debug mode. In fact, I can find
> the value of my hiddenfield by using
> (this.Page.Request.Form.GetValues(base.ID + "_hidden"))[0], but the value
> is
> not the good one. The value is the orignal one (before any modification in
> javascript). I can't get the value modified by the javascript.
> I cannot use FindControl because at this time, the object is not yet
> "re-created" (after submit but before render).
>
> Regards and thank you again,
> Fabien.
>
> a écrit dans le message de news:
> 86EB63DB-35C8-494E-BD4B-BD10203F1...@microsoft.com...
>
>
>
> > Hi,
>
> > it's simple, find the HiddenField in page (you can get the current page
> > instance by anyControl.Page), every control has a FindControl method
> > (but
> > it searches only his childs not childs of his childs.....) so if the
> > hiddenField is somewhere deep, you will have use recursion to find the
> > control. Then you will get it's value by yourHiddenField.Value
>
> > Regards,
>
> > Lukas Holota
>
> > "Fabien Henriet" wrote in message
> >news:eRpxBE6RIHA.5360@TK2MSFTNGP03.phx.gbl...
> >> Thank you for your quick answer!
> >> I've already thought to use an hiddenfield. But I don't know how to get
> >> the value of this field in my extended control.
>
> >> I explain: when I submit my form, I call a method of my extended
> >> textbox
> >> and within this method, I would like to test the value of my
> >> hiddenfield.
> >> I prefer not to make that test in code behind of my page.
>
> >> Thanks in advance for your help.
>
> >> Fabien.
>
> >> "Hal Rosser" a écrit dans le message de news:
> >> fjhcj.30637$vt2.27...@bignews8.bellsouth.net...
>
> >>> "Fabien Henriet" wrote in message
> >>>news:e%23y8oo0RIHA.1188@TK2MSFTNGP04.phx.gbl...
> >>>> Hello,
>
> >>>> I got a problem when I try to extend a textbox.
> >>>> So I overwrite the Render method. For the stuff I try to do, I would
> >>>> like to add a custom attribute to my customized textbox.
> >>>> So it renders something like this:
> >>>>
>
> >>>> I modify the value of "myattribute" using javascript, but when I
> >>>> submit
> >>>> my form, I can't get the value of "myattribute".
>
> >>>> Do I have to create create a class extended the attribute class? How
> >>>> do I have to proceed?
>
> >>>> Thank you in advance,
> >>>> Fabien.
>
> >>> When you submit the form, each form element with a "name" attribute
> >>> and
> >>> a "value" attribute will be sent as a 'pair' or 'set' of name=value
> >>> pairs. For example
> >>> this element will provide color=blue.
> >>> HTH- Hide quoted text -
>
> - Show quoted text -
Re: Extended control issue
am 27.12.2007 09:14:59 von mark
"Fabien Henriet" wrote in message
news:%23N3eP6FSIHA.6060@TK2MSFTNGP05.phx.gbl...
> Thank you for your answer, but I'm not sure to understand the difference
> between base.Id and this.ClientID... Both of those strings will return
> the same value... I can get back the id or name of my hiddenfield, I
> can't get back the value of this item assigned client-side.
Does this thread help?
http://forums.asp.net/p/1039574/1444169.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Re: Extended control issue
am 27.12.2007 09:45:36 von Fabien Henriet
Hi Mark,
Yes and No. I explain. I render the hiddenfield this way:
HiddenField hiddenField = new HiddenField();
hiddenField.ID = base.ID + "_hidden";
hiddenField.EnableViewState = true;
hiddenField.Value = false.ToString();
hiddenField.RenderControl(writer);
This is in my "protected override void Render(System.Web.UI.HtmlTextWriter
writer)" method of my extended textbox. How to specify "runat=server"?
During postback my value is the one I set in hiddenField.Value, not the one
javascript set.
Any idea?
Thank in advance,
Fabien.
"Mark Rae [MVP]" a écrit dans le message de news:
uYbYHCGSIHA.1208@TK2MSFTNGP03.phx.gbl...
> "Fabien Henriet" wrote in message
> news:%23N3eP6FSIHA.6060@TK2MSFTNGP05.phx.gbl...
>
>> Thank you for your answer, but I'm not sure to understand the difference
>> between base.Id and this.ClientID... Both of those strings will return
>> the same value... I can get back the id or name of my hiddenfield, I
>> can't get back the value of this item assigned client-side.
>
> Does this thread help?
> http://forums.asp.net/p/1039574/1444169.aspx
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
Re: Extended control issue
am 27.12.2007 10:27:21 von mark
"Fabien Henriet" wrote in message
news:uycCgTGSIHA.5128@TK2MSFTNGP05.phx.gbl...
> I render the hiddenfield this way:
Why? Have you tried simply to add the hidden field to your UserControl's
markup just like any other control...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Re: Extended control issue
am 27.12.2007 10:49:51 von Fabien Henriet
Hello Mark,
I try to create our own custom controls and I would like to make it the most
generic you can have. We create a lot of controls to use in web pages.
It's a kind of central project used in all our websites.
Anyway, we thought a lot over that and the best way for us was to extend
TextBox class and so on... So we took this way.
I can't imagine you cannot add some attributes to an object. If I modify
Text attribute, I can get its value, why can't I do that with another
property? I heard about custom attributes. I defined my own attribute and
try to use it in my class. I can change the value within javascript. But
do you know how to get the value server-side?
Can you give me a good tutorial with custom attributes and confirm me I can
use them to solve my problem?
Thank you in advance,
Fabien.
"Mark Rae [MVP]" a écrit dans le message de news:
egaqjqGSIHA.1188@TK2MSFTNGP04.phx.gbl...
> "Fabien Henriet" wrote in message
> news:uycCgTGSIHA.5128@TK2MSFTNGP05.phx.gbl...
>
>> I render the hiddenfield this way:
>
> Why? Have you tried simply to add the hidden field to your UserControl's
> markup just like any other control...?
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net
Re: Extended control issue
am 27.12.2007 12:49:15 von mark
"Fabien Henriet" wrote in message
news:eKXrZ3GSIHA.4684@TK2MSFTNGP06.phx.gbl...
> Anyway, we thought a lot over that and the best way for us was to extend
> TextBox class and so on...
Why?
> I can't imagine you cannot add some attributes to an object.
You can...
> If I modify Text attribute, I can get its value, why can't I do that with
> another property?
The Text attribute already exists for the TextBox control. I think the
problem is that you are modifying the TextBox control far too late in the
page lifecycle. Generally speaking, custom controls need to be created no
later than Page_Init...
> Can you give me a good tutorial with custom attributes and confirm me I
> can use them to solve my problem?
Create a UserControl which contains a TextBox and a HiddenField, and your
problems will disappear...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Re: Extended control issue
am 27.12.2007 13:08:15 von Fabien Henriet
Thank you for your kind help, I'll do that.
Regards,
Fabien.
"Mark Rae [MVP]" a écrit dans le message de news:
OrCf25HSIHA.6036@TK2MSFTNGP03.phx.gbl...
> "Fabien Henriet" wrote in message
> news:eKXrZ3GSIHA.4684@TK2MSFTNGP06.phx.gbl...
>
>> Anyway, we thought a lot over that and the best way for us was to extend
>> TextBox class and so on...
>
> Why?
>
>> I can't imagine you cannot add some attributes to an object.
>
> You can...
>
>> If I modify Text attribute, I can get its value, why can't I do that with
>> another property?
>
> The Text attribute already exists for the TextBox control. I think the
> problem is that you are modifying the TextBox control far too late in the
> page lifecycle. Generally speaking, custom controls need to be created no
> later than Page_Init...
>
>> Can you give me a good tutorial with custom attributes and confirm me I
>> can use them to solve my problem?
>
> Create a UserControl which contains a TextBox and a HiddenField, and your
> problems will disappear...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net