a growing dislike of custom user controls

Discussion in 'ASP .Net' started by V. Jenks, Apr 28, 2004.

  1. V. Jenks

    V. Jenks Guest

    Long story as short as possible:

    I have a page (aspx) that contains a user control
    (ascx). In the form the user can enter a username and
    password. If they do, the password box auto-posts-back
    and checks to see if the user already exists in the
    database.

    If yes, the rest of the form fields on the page are
    populated with that existing user's data.

    If no, nothing happens, of course.

    Everything works fine until I fire the submit button at
    the bottom of the form. In the OnClick event handler for
    the button, data is inserted and the user is redirected.

    However, the event handler isn't fired first, for SOME
    reason, the ontextchanged event handler for the password
    box gets fired first, screws up my page, and creates a
    bunch of errors.

    First of all, why does that event fire when nothing
    changes about this particular field that would fire the
    event?

    By all means, the OnClick event handler should be getting
    fired, and it does, but only *after* the OnTextChanged
    for the password box is fired (when logically, it
    shouldn't have!)

    Any ideas?

    Thanks ahead of time!

    -v
    V. Jenks, Apr 28, 2004
    #1
    1. Advertising

  2. Probably not much help to you, but I find explicitly configuing custom event/postback requirements for ascx controls is a pain in the arse. I've given up on it. ASP.NET server controls that only do a postback you're fine with, but anything else and you might aswell just copy the html and paste it.
    =?Utf-8?B?QjBuag==?=, Apr 28, 2004
    #2
    1. Advertising

  3. Hopefully, the following link should be of some help with your sequence
    issue:

    http://msdn.microsoft.com/library/d...guide/html/cpconControlExecutionLifecycle.asp

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "V. Jenks" <> wrote in message
    news:55ea01c42d07$5057f860$...
    > Long story as short as possible:
    >
    > I have a page (aspx) that contains a user control
    > (ascx). In the form the user can enter a username and
    > password. If they do, the password box auto-posts-back
    > and checks to see if the user already exists in the
    > database.
    >
    > If yes, the rest of the form fields on the page are
    > populated with that existing user's data.
    >
    > If no, nothing happens, of course.
    >
    > Everything works fine until I fire the submit button at
    > the bottom of the form. In the OnClick event handler for
    > the button, data is inserted and the user is redirected.
    >
    > However, the event handler isn't fired first, for SOME
    > reason, the ontextchanged event handler for the password
    > box gets fired first, screws up my page, and creates a
    > bunch of errors.
    >
    > First of all, why does that event fire when nothing
    > changes about this particular field that would fire the
    > event?
    >
    > By all means, the OnClick event handler should be getting
    > fired, and it does, but only *after* the OnTextChanged
    > for the password box is fired (when logically, it
    > shouldn't have!)
    >
    > Any ideas?
    >
    > Thanks ahead of time!
    >
    > -v
    Kevin Spencer, Apr 28, 2004
    #3
  4. V. Jenks

    matt Guest

    I'm not sure but if this is relevant by might the root of this problem
    in the way password fields are handled? You said the ontextchanged gets
    fired even when the password hasn't changed. The password field will
    always be blank on the form (as you can't populate a password field with
    a value in html), until something is entered in the field. If you set a
    value to a password field then it would always be changed unless someone
    physically types the same value in to the password box on your form,
    otherwise it would be considered to have changed as it will be posted
    back as blank.

    Not sure if that will be any help or not, but from your message it
    sounds like a possible cause.

    Matt
    http://www.3internet.co.uk


    "V. Jenks" <> wrote in message
    news:55ea01c42d07$5057f860$...
    > Long story as short as possible:
    >
    > I have a page (aspx) that contains a user control
    > (ascx). In the form the user can enter a username and
    > password. If they do, the password box auto-posts-back
    > and checks to see if the user already exists in the
    > database.
    >
    > If yes, the rest of the form fields on the page are
    > populated with that existing user's data.
    >
    > If no, nothing happens, of course.
    >
    > Everything works fine until I fire the submit button at
    > the bottom of the form. In the OnClick event handler for
    > the button, data is inserted and the user is redirected.
    >
    > However, the event handler isn't fired first, for SOME
    > reason, the ontextchanged event handler for the password
    > box gets fired first, screws up my page, and creates a
    > bunch of errors.
    >
    > First of all, why does that event fire when nothing
    > changes about this particular field that would fire the
    > event?
    >
    > By all means, the OnClick event handler should be getting
    > fired, and it does, but only *after* the OnTextChanged
    > for the password box is fired (when logically, it
    > shouldn't have!)
    >
    > Any ideas?
    >
    > Thanks ahead of time!
    >
    > -v
    matt, Apr 28, 2004
    #4
  5. V. Jenks

    V. Jenks Guest

    Yes you can, by adding an attribute to the password
    TextBox control (TextBox.Attributes.Add("value", item);)

    This is what I'm doing, however, I'm encrypting it so it
    can't be viewed by viewing the source.

    Anyhow, that's irrelevant. Why isn't the button's click
    event firing *first*!?


    >-----Original Message-----
    >I'm not sure but if this is relevant by might the root

    of this problem
    >in the way password fields are handled? You said the

    ontextchanged gets
    >fired even when the password hasn't changed. The

    password field will
    >always be blank on the form (as you can't populate a

    password field with
    >a value in html), until something is entered in the

    field. If you set a
    >value to a password field then it would always be

    changed unless someone
    >physically types the same value in to the password box

    on your form,
    >otherwise it would be considered to have changed as it

    will be posted
    >back as blank.
    >
    >Not sure if that will be any help or not, but from your

    message it
    >sounds like a possible cause.
    >
    >Matt
    >http://www.3internet.co.uk
    >
    >
    >"V. Jenks" <> wrote in message
    >news:55ea01c42d07$5057f860$...
    >> Long story as short as possible:
    >>
    >> I have a page (aspx) that contains a user control
    >> (ascx). In the form the user can enter a username and
    >> password. If they do, the password box auto-posts-back
    >> and checks to see if the user already exists in the
    >> database.
    >>
    >> If yes, the rest of the form fields on the page are
    >> populated with that existing user's data.
    >>
    >> If no, nothing happens, of course.
    >>
    >> Everything works fine until I fire the submit button at
    >> the bottom of the form. In the OnClick event handler

    for
    >> the button, data is inserted and the user is

    redirected.
    >>
    >> However, the event handler isn't fired first, for SOME
    >> reason, the ontextchanged event handler for the

    password
    >> box gets fired first, screws up my page, and creates a
    >> bunch of errors.
    >>
    >> First of all, why does that event fire when nothing
    >> changes about this particular field that would fire the
    >> event?
    >>
    >> By all means, the OnClick event handler should be

    getting
    >> fired, and it does, but only *after* the OnTextChanged
    >> for the password box is fired (when logically, it
    >> shouldn't have!)
    >>
    >> Any ideas?
    >>
    >> Thanks ahead of time!
    >>
    >> -v

    >
    >
    >.
    >
    V. Jenks, Apr 28, 2004
    #5
  6. V. Jenks

    matt Guest

    Yes good point! Not sure why I had thought the password couldn't have a
    value assigned to it, although it's logical that you shouldn't be able
    to as you say otherwise it's left to you to ensure any encryption, and
    this is why you when you set the Text property that no value attribute
    is output.

    Having said that I think it's still the root of you problem. Setting
    the value attribute using the syntax you mention is different to setting
    the text value. It is the Text property of the textbox that is checked
    against to determine the ontextchange event.

    I suspect that if you change your code to set the Text property of the
    password field as well as adding the value attribute to the password
    field then you would find the ontextchanged event will not fire for the
    password field, if it does then a workaround is to check whether the
    button has been clicked.

    One other thing I am not sure why you expect the onclick event to always
    fire first.

    Matt


    "V. Jenks" <> wrote in message
    news:5afc01c42d56$10306160$...
    > Yes you can, by adding an attribute to the password
    > TextBox control (TextBox.Attributes.Add("value", item);)
    >
    > This is what I'm doing, however, I'm encrypting it so it
    > can't be viewed by viewing the source.
    >
    > Anyhow, that's irrelevant. Why isn't the button's click
    > event firing *first*!?
    >
    >
    > >-----Original Message-----
    > >I'm not sure but if this is relevant by might the root

    > of this problem
    > >in the way password fields are handled? You said the

    > ontextchanged gets
    > >fired even when the password hasn't changed. The

    > password field will
    > >always be blank on the form (as you can't populate a

    > password field with
    > >a value in html), until something is entered in the

    > field. If you set a
    > >value to a password field then it would always be

    > changed unless someone
    > >physically types the same value in to the password box

    > on your form,
    > >otherwise it would be considered to have changed as it

    > will be posted
    > >back as blank.
    > >
    > >Not sure if that will be any help or not, but from your

    > message it
    > >sounds like a possible cause.
    > >
    > >Matt
    > >http://www.3internet.co.uk
    > >
    > >
    > >"V. Jenks" <> wrote in message
    > >news:55ea01c42d07$5057f860$...
    > >> Long story as short as possible:
    > >>
    > >> I have a page (aspx) that contains a user control
    > >> (ascx). In the form the user can enter a username and
    > >> password. If they do, the password box auto-posts-back
    > >> and checks to see if the user already exists in the
    > >> database.
    > >>
    > >> If yes, the rest of the form fields on the page are
    > >> populated with that existing user's data.
    > >>
    > >> If no, nothing happens, of course.
    > >>
    > >> Everything works fine until I fire the submit button at
    > >> the bottom of the form. In the OnClick event handler

    > for
    > >> the button, data is inserted and the user is

    > redirected.
    > >>
    > >> However, the event handler isn't fired first, for SOME
    > >> reason, the ontextchanged event handler for the

    > password
    > >> box gets fired first, screws up my page, and creates a
    > >> bunch of errors.
    > >>
    > >> First of all, why does that event fire when nothing
    > >> changes about this particular field that would fire the
    > >> event?
    > >>
    > >> By all means, the OnClick event handler should be

    > getting
    > >> fired, and it does, but only *after* the OnTextChanged
    > >> for the password box is fired (when logically, it
    > >> shouldn't have!)
    > >>
    > >> Any ideas?
    > >>
    > >> Thanks ahead of time!
    > >>
    > >> -v

    > >
    > >
    > >.
    > >
    matt, Apr 29, 2004
    #6
    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. ben
    Replies:
    3
    Views:
    509
    Kevin Spencer
    Nov 15, 2004
  2. Kyler Laird
    Replies:
    0
    Views:
    284
    Kyler Laird
    Jan 18, 2004
  3. Stefan Reich

    I strongly dislike Python 3

    Stefan Reich, Jun 26, 2010, in forum: Python
    Replies:
    1
    Views:
    294
    Lawrence D'Oliveiro
    Jun 27, 2010
  4. Thomas Jollans

    Re: I strongly dislike Python 3

    Thomas Jollans, Jun 26, 2010, in forum: Python
    Replies:
    52
    Views:
    1,491
    Chris Rebert
    Jul 2, 2010
  5. Stefan Reich

    Re: I strongly dislike Python 3

    Stefan Reich, Jun 26, 2010, in forum: Python
    Replies:
    5
    Views:
    379
    Stephen Hansen
    Jun 27, 2010
Loading...

Share This Page