Extended control issue

Discussion in 'ASP .Net' started by Fabien Henriet, Dec 25, 2007.

  1. 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:
    <input ... myattribute="value" />

    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.
    Fabien Henriet, Dec 25, 2007
    #1
    1. Advertising

  2. Fabien Henriet

    Hal Rosser Guest

    "Fabien Henriet" <> wrote in message
    news:e%...
    > 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:
    > <input ... myattribute="value" />
    >
    > 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 <input type="hidden" name="color" value="blue" /> this element will
    provide color=blue.
    HTH
    Hal Rosser, Dec 26, 2007
    #2
    1. Advertising

  3. 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$...
    >
    > "Fabien Henriet" <> wrote in message
    > news:e%...
    >> 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:
    >> <input ... myattribute="value" />
    >>
    >> 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 <input type="hidden" name="color" value="blue" /> this
    > element will provide color=blue.
    > HTH
    >
    Fabien Henriet, Dec 26, 2007
    #3
  4. Fabien Henriet

    Guest Guest

    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:...
    > 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$...
    >>
    >> "Fabien Henriet" <> wrote in message
    >> news:e%...
    >>> 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:
    >>> <input ... myattribute="value" />
    >>>
    >>> 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 <input type="hidden" name="color" value="blue" /> this
    >> element will provide color=blue.
    >> HTH
    >>

    >
    >
    Guest, Dec 26, 2007
    #4
  5. 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:
    ...
    > 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:...
    >> 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$...
    >>>
    >>> "Fabien Henriet" <> wrote in message
    >>> news:e%...
    >>>> 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:
    >>>> <input ... myattribute="value" />
    >>>>
    >>>> 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 <input type="hidden" name="color" value="blue" />
    >>> this element will provide color=blue.
    >>> HTH
    >>>

    >>
    >>
    Fabien Henriet, Dec 26, 2007
    #5
  6. 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:
    > ...
    >
    >
    >
    > > 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:...
    > >> 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$...

    >
    > >>> "Fabien Henriet" <> wrote in message
    > >>>news:e%...
    > >>>> 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:
    > >>>> <input ... myattribute="value" />

    >
    > >>>> 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 <input type="hidden" name="color" value="blue" />
    > >>> this element will provide color=blue.
    > >>> HTH- Hide quoted text -

    >
    > - Show quoted text -
    PJ on Development, Dec 26, 2007
    #6
  7. 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: ...
    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:
    > ...
    >
    >
    >
    > > 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:...
    > >> 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$...

    >
    > >>> "Fabien Henriet" <> wrote in message
    > >>>news:e%...
    > >>>> 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:
    > >>>> <input ... myattribute="value" />

    >
    > >>>> 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 <input type="hidden" name="color" value="blue" />
    > >>> this element will provide color=blue.
    > >>> HTH- Hide quoted text -

    >
    > - Show quoted text -
    Fabien Henriet, Dec 27, 2007
    #7
  8. "Fabien Henriet" <> wrote in message
    news:%...

    > 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
    Mark Rae [MVP], Dec 27, 2007
    #8
  9. 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:
    ...
    > "Fabien Henriet" <> wrote in message
    > news:%...
    >
    >> 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
    Fabien Henriet, Dec 27, 2007
    #9
  10. "Fabien Henriet" <> wrote in message
    news:...

    > 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
    Mark Rae [MVP], Dec 27, 2007
    #10
  11. 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:
    ...
    > "Fabien Henriet" <> wrote in message
    > news:...
    >
    >> 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
    Fabien Henriet, Dec 27, 2007
    #11
  12. "Fabien Henriet" <> wrote in message
    news:...

    > 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
    Mark Rae [MVP], Dec 27, 2007
    #12
  13. Thank you for your kind help, I'll do that.

    Regards,
    Fabien.

    "Mark Rae [MVP]" <> a écrit dans le message de news:
    ...
    > "Fabien Henriet" <> wrote in message
    > news:...
    >
    >> 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
    Fabien Henriet, Dec 27, 2007
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. buran
    Replies:
    2
    Views:
    816
    buran
    Dec 29, 2004
  2. Replies:
    3
    Views:
    474
    Eliyahu Goldin
    Sep 1, 2005
  3. Replies:
    0
    Views:
    997
  4. Stefaan V.

    Serialize Extended Properties in a web control

    Stefaan V., Sep 29, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    140
    Stefaan V.
    Sep 29, 2004
  5. buran
    Replies:
    2
    Views:
    216
    John Saunders
    Dec 20, 2004
Loading...

Share This Page