HtmlSelect and RequiredFieldValidator

Discussion in 'ASP .Net' started by BK, May 3, 2005.

  1. BK

    BK Guest

    I'm having a really strange problem with and HtmlSelect server control
    (listbox) and a RequiredFieldValidator that I am trying to use to make sure
    that someone has items in the listbox.

    The way that the HtmlSelect is populated is via a combination of client-side
    javascript and another aspx page (launched by the javascript).

    Anyway, everything seems to work just fine in terms of populating the
    HtmlSelect. However, when I postback the form, the RequiredFieldValidator
    always thinks that there is nothing in the HtmlSelect and fails validation
    (I am only using server-side validation, by the way). I have the
    ControlToValidate and all those things hooked up properly. Is there some
    trick to setting the RequiredFieldValidator for an HtmlSelect control? Some
    property that I am not setting?? I suspect that there is some small setting
    that I am missing, but I have spent way too much time on this to keep
    struggling.

    Any help is appreciated,
    Thanks
     
    BK, May 3, 2005
    #1
    1. Advertising

  2. BK

    Karl Seguin Guest

    I wouldn't expect server-side validation to work on client-side added items.

    Take a look at: http://openmymind.net/FAQ.aspx?documentId=1

    but the quick answer is that when you add items in javascript, they aren't
    added to the viewstate which means they won't be recreated on
    postback...explains why your htmlselect is empty...

    Karl


    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)


    "BK" <> wrote in message
    news:...
    > I'm having a really strange problem with and HtmlSelect server control
    > (listbox) and a RequiredFieldValidator that I am trying to use to make
    > sure
    > that someone has items in the listbox.
    >
    > The way that the HtmlSelect is populated is via a combination of
    > client-side
    > javascript and another aspx page (launched by the javascript).
    >
    > Anyway, everything seems to work just fine in terms of populating the
    > HtmlSelect. However, when I postback the form, the RequiredFieldValidator
    > always thinks that there is nothing in the HtmlSelect and fails validation
    > (I am only using server-side validation, by the way). I have the
    > ControlToValidate and all those things hooked up properly. Is there some
    > trick to setting the RequiredFieldValidator for an HtmlSelect control?
    > Some
    > property that I am not setting?? I suspect that there is some small
    > setting
    > that I am missing, but I have spent way too much time on this to keep
    > struggling.
    >
    > Any help is appreciated,
    > Thanks
    >
    >
     
    Karl Seguin, May 3, 2005
    #2
    1. Advertising

  3. Patrick Olurotimi Ige, May 3, 2005
    #3
  4. BK

    BK Guest

    OK, this sort of makes sense to me. But, all the documentation that I have
    read says that the RequiredFieldValidator works with an HtmlSelect server
    control. I guess what you are saying is that the items need to be added
    server-side for this to work?

    Also, if this is the case, then is there a way to add them to the viewstate
    in the described scenario or will I have to do some kind of convoluted
    CustomValidation where I check the Request collection? Based upon the FAQ
    below, I am assuming that converting to web controls wouldn't solve the
    problem either - this seems to be a client vs server side issue with regard
    to how the validation works.

    Brian

    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:uP$6M$...
    > I wouldn't expect server-side validation to work on client-side added

    items.
    >
    > Take a look at: http://openmymind.net/FAQ.aspx?documentId=1
    >
    > but the quick answer is that when you add items in javascript, they aren't
    > added to the viewstate which means they won't be recreated on
    > postback...explains why your htmlselect is empty...
    >
    > Karl
    >
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    >
    >
    > "BK" <> wrote in message
    > news:...
    > > I'm having a really strange problem with and HtmlSelect server control
    > > (listbox) and a RequiredFieldValidator that I am trying to use to make
    > > sure
    > > that someone has items in the listbox.
    > >
    > > The way that the HtmlSelect is populated is via a combination of
    > > client-side
    > > javascript and another aspx page (launched by the javascript).
    > >
    > > Anyway, everything seems to work just fine in terms of populating the
    > > HtmlSelect. However, when I postback the form, the

    RequiredFieldValidator
    > > always thinks that there is nothing in the HtmlSelect and fails

    validation
    > > (I am only using server-side validation, by the way). I have the
    > > ControlToValidate and all those things hooked up properly. Is there some
    > > trick to setting the RequiredFieldValidator for an HtmlSelect control?
    > > Some
    > > property that I am not setting?? I suspect that there is some small
    > > setting
    > > that I am missing, but I have spent way too much time on this to keep
    > > struggling.
    > >
    > > Any help is appreciated,
    > > Thanks
    > >
    > >

    >
    >
     
    BK, May 3, 2005
    #4
  5. BK

    BK Guest

    Well, it doesn't sound like it has anything to do with HtmlSelect, per se,
    validating. It seems like it has to do with the values not being in
    Viewstate. If that is the case, then validation would not work with ANY
    items that are added to a form via client-side code.

    "Patrick Olurotimi Ige" <> wrote in message
    news:%...
    > As Karl explained don't expect HtmlSelect to validate
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
     
    BK, May 3, 2005
    #5
  6. BK

    Karl Seguin Guest

    You are pretty much right about everything. Though I would expect the
    client-side validation to still work (not necessarily ideal since it only
    works in IE...)

    -items need to be added server-side
    -going to dropdownlist (server control) wouldn't change anything
    -you'll need to write your own validator and use request.form

    Cheers,
    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "BK" <> wrote in message
    news:O3Fu5l%...
    > OK, this sort of makes sense to me. But, all the documentation that I have
    > read says that the RequiredFieldValidator works with an HtmlSelect server
    > control. I guess what you are saying is that the items need to be added
    > server-side for this to work?
    >
    > Also, if this is the case, then is there a way to add them to the
    > viewstate
    > in the described scenario or will I have to do some kind of convoluted
    > CustomValidation where I check the Request collection? Based upon the FAQ
    > below, I am assuming that converting to web controls wouldn't solve the
    > problem either - this seems to be a client vs server side issue with
    > regard
    > to how the validation works.
    >
    > Brian
    >
    > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    > wrote in message news:uP$6M$...
    >> I wouldn't expect server-side validation to work on client-side added

    > items.
    >>
    >> Take a look at: http://openmymind.net/FAQ.aspx?documentId=1
    >>
    >> but the quick answer is that when you add items in javascript, they
    >> aren't
    >> added to the viewstate which means they won't be recreated on
    >> postback...explains why your htmlselect is empty...
    >>
    >> Karl
    >>
    >>
    >> --
    >> MY ASP.Net tutorials
    >> http://www.openmymind.net/ - New and Improved (yes, the popup is
    >> annoying)
    >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    >> come!)
    >>
    >>
    >> "BK" <> wrote in message
    >> news:...
    >> > I'm having a really strange problem with and HtmlSelect server control
    >> > (listbox) and a RequiredFieldValidator that I am trying to use to make
    >> > sure
    >> > that someone has items in the listbox.
    >> >
    >> > The way that the HtmlSelect is populated is via a combination of
    >> > client-side
    >> > javascript and another aspx page (launched by the javascript).
    >> >
    >> > Anyway, everything seems to work just fine in terms of populating the
    >> > HtmlSelect. However, when I postback the form, the

    > RequiredFieldValidator
    >> > always thinks that there is nothing in the HtmlSelect and fails

    > validation
    >> > (I am only using server-side validation, by the way). I have the
    >> > ControlToValidate and all those things hooked up properly. Is there
    >> > some
    >> > trick to setting the RequiredFieldValidator for an HtmlSelect control?
    >> > Some
    >> > property that I am not setting?? I suspect that there is some small
    >> > setting
    >> > that I am missing, but I have spent way too much time on this to keep
    >> > struggling.
    >> >
    >> > Any help is appreciated,
    >> > Thanks
    >> >
    >> >

    >>
    >>

    >
    >
     
    Karl Seguin, May 3, 2005
    #6
  7. BK

    Brock Allen Guest

    > OK, this sort of makes sense to me. But, all the documentation that I
    > have read says that the RequiredFieldValidator works with an
    > HtmlSelect server control. I guess what you are saying is that the
    > items need to be added server-side for this to work?


    Yes, you're correct. If you look at the javascript emitted when you do have
    server side validation controls you'll see there's an array that's initalized
    at the bottom somewhere with the IDs of all the client side validation elements.
    This is what the client side framework drives off of.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen
     
    Brock Allen, May 3, 2005
    #7
  8. BK

    BK Guest

    I'm still having trouble with this, here is what I have done (I'm not using
    client-side validation, by the way - customer requirement):

    1) As I mentioned before, everything works fine client-side in terms of
    items being added to the HtmlSelect control. I get a nice list of items in
    my form, as expected. In addition, I have a hidden input field that holds a
    string representation of the values, so that I can persist between
    postbacks. For the sake of argument, lets call my HtmlSelect (which is
    runat=server) "lstValues" and my hidden input (which is also runat=server)
    "hdnValues".

    2) Now, from what I understand, I should be able to truly populate the
    HtmlSelect control (as .NET sees it) on the server-side, so that when
    validation rolls around in the page event cycle, it will see that items have
    been added. This is where confusion sets in.

    3) It seems that Page_Init is too early to set any values because
    "hdnValues" is always an empty string. So, that doesn't work.

    4) I have tried adding IPostbackDataHandler to my page and implementing
    LoadPostbackData, but this doesn't seem to work. The values are set, but the
    validation still fails.

    5) I have tried adding multiple other events that supposedly occur before
    validation and populating lstValues there, but all to no avail. Validation
    still fails.

    6) I have googled and read everything that I can find, but nothing seem to
    work.

    This cannot be this difficult. I feel like I have all that I need on the
    client-side, I just need to know what to do and where to do it in the
    code-behind in order to catch the page event before validation and populate
    lstValues with the items that I have. Also, from what I understand (and I
    have observed the problem, so I know its true) CustomValidators don't work
    with HtmlSelect - the event doesn't fire, so that is not an option either.

    Any help is appreciated, I have been working on this all day....

    TIA
    BK

    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:OtuCBM$...
    > You are pretty much right about everything. Though I would expect the
    > client-side validation to still work (not necessarily ideal since it only
    > works in IE...)
    >
    > -items need to be added server-side
    > -going to dropdownlist (server control) wouldn't change anything
    > -you'll need to write your own validator and use request.form
    >
    > Cheers,
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    > "BK" <> wrote in message
    > news:O3Fu5l%...
    > > OK, this sort of makes sense to me. But, all the documentation that I

    have
    > > read says that the RequiredFieldValidator works with an HtmlSelect

    server
    > > control. I guess what you are saying is that the items need to be added
    > > server-side for this to work?
    > >
    > > Also, if this is the case, then is there a way to add them to the
    > > viewstate
    > > in the described scenario or will I have to do some kind of convoluted
    > > CustomValidation where I check the Request collection? Based upon the

    FAQ
    > > below, I am assuming that converting to web controls wouldn't solve the
    > > problem either - this seems to be a client vs server side issue with
    > > regard
    > > to how the validation works.
    > >
    > > Brian
    > >
    > > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    > > wrote in message news:uP$6M$...
    > >> I wouldn't expect server-side validation to work on client-side added

    > > items.
    > >>
    > >> Take a look at: http://openmymind.net/FAQ.aspx?documentId=1
    > >>
    > >> but the quick answer is that when you add items in javascript, they
    > >> aren't
    > >> added to the viewstate which means they won't be recreated on
    > >> postback...explains why your htmlselect is empty...
    > >>
    > >> Karl
    > >>
    > >>
    > >> --
    > >> MY ASP.Net tutorials
    > >> http://www.openmymind.net/ - New and Improved (yes, the popup is
    > >> annoying)
    > >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > >> come!)
    > >>
    > >>
    > >> "BK" <> wrote in message
    > >> news:...
    > >> > I'm having a really strange problem with and HtmlSelect server

    control
    > >> > (listbox) and a RequiredFieldValidator that I am trying to use to

    make
    > >> > sure
    > >> > that someone has items in the listbox.
    > >> >
    > >> > The way that the HtmlSelect is populated is via a combination of
    > >> > client-side
    > >> > javascript and another aspx page (launched by the javascript).
    > >> >
    > >> > Anyway, everything seems to work just fine in terms of populating the
    > >> > HtmlSelect. However, when I postback the form, the

    > > RequiredFieldValidator
    > >> > always thinks that there is nothing in the HtmlSelect and fails

    > > validation
    > >> > (I am only using server-side validation, by the way). I have the
    > >> > ControlToValidate and all those things hooked up properly. Is there
    > >> > some
    > >> > trick to setting the RequiredFieldValidator for an HtmlSelect

    control?
    > >> > Some
    > >> > property that I am not setting?? I suspect that there is some small
    > >> > setting
    > >> > that I am missing, but I have spent way too much time on this to keep
    > >> > struggling.
    > >> >
    > >> > Any help is appreciated,
    > >> > Thanks
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
     
    BK, May 4, 2005
    #8
  9. BK

    BK Guest

    Thanks. I'm still having problems with this - I posted the details in a
    previous message. Everything on the client side of the house works fine. I
    just cannot seem to figure out what to do on the server side to convince
    ..NET that there is something in the HtmlSelect. I have tried MANY different
    ways and all of them fail validation.

    "Brock Allen" <> wrote in message
    news:...
    > > OK, this sort of makes sense to me. But, all the documentation that I
    > > have read says that the RequiredFieldValidator works with an
    > > HtmlSelect server control. I guess what you are saying is that the
    > > items need to be added server-side for this to work?

    >
    > Yes, you're correct. If you look at the javascript emitted when you do

    have
    > server side validation controls you'll see there's an array that's

    initalized
    > at the bottom somewhere with the IDs of all the client side validation

    elements.
    > This is what the client side framework drives off of.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
     
    BK, May 4, 2005
    #9
  10. BK

    Karl Seguin Guest

    The information will be available in the Page_Load event. It's loaded in
    the LoadPostbackData event of the individual contorl - not the pages.

    Why not just write your own validation event....By the time you get to a
    bottom's click event, the data is there, write a function "IsCustomValide()"
    which checks to see if hdnValues has a value?

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "BK" <> wrote in message
    news:...
    > I'm still having trouble with this, here is what I have done (I'm not
    > using
    > client-side validation, by the way - customer requirement):
    >
    > 1) As I mentioned before, everything works fine client-side in terms of
    > items being added to the HtmlSelect control. I get a nice list of items in
    > my form, as expected. In addition, I have a hidden input field that holds
    > a
    > string representation of the values, so that I can persist between
    > postbacks. For the sake of argument, lets call my HtmlSelect (which is
    > runat=server) "lstValues" and my hidden input (which is also runat=server)
    > "hdnValues".
    >
    > 2) Now, from what I understand, I should be able to truly populate the
    > HtmlSelect control (as .NET sees it) on the server-side, so that when
    > validation rolls around in the page event cycle, it will see that items
    > have
    > been added. This is where confusion sets in.
    >
    > 3) It seems that Page_Init is too early to set any values because
    > "hdnValues" is always an empty string. So, that doesn't work.
    >
    > 4) I have tried adding IPostbackDataHandler to my page and implementing
    > LoadPostbackData, but this doesn't seem to work. The values are set, but
    > the
    > validation still fails.
    >
    > 5) I have tried adding multiple other events that supposedly occur before
    > validation and populating lstValues there, but all to no avail. Validation
    > still fails.
    >
    > 6) I have googled and read everything that I can find, but nothing seem to
    > work.
    >
    > This cannot be this difficult. I feel like I have all that I need on the
    > client-side, I just need to know what to do and where to do it in the
    > code-behind in order to catch the page event before validation and
    > populate
    > lstValues with the items that I have. Also, from what I understand (and I
    > have observed the problem, so I know its true) CustomValidators don't work
    > with HtmlSelect - the event doesn't fire, so that is not an option either.
    >
    > Any help is appreciated, I have been working on this all day....
    >
    > TIA
    > BK
    >
    > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    > wrote in message news:OtuCBM$...
    >> You are pretty much right about everything. Though I would expect the
    >> client-side validation to still work (not necessarily ideal since it only
    >> works in IE...)
    >>
    >> -items need to be added server-side
    >> -going to dropdownlist (server control) wouldn't change anything
    >> -you'll need to write your own validator and use request.form
    >>
    >> Cheers,
    >> Karl
    >>
    >> --
    >> MY ASP.Net tutorials
    >> http://www.openmymind.net/ - New and Improved (yes, the popup is
    >> annoying)
    >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    >> come!)
    >> "BK" <> wrote in message
    >> news:O3Fu5l%...
    >> > OK, this sort of makes sense to me. But, all the documentation that I

    > have
    >> > read says that the RequiredFieldValidator works with an HtmlSelect

    > server
    >> > control. I guess what you are saying is that the items need to be added
    >> > server-side for this to work?
    >> >
    >> > Also, if this is the case, then is there a way to add them to the
    >> > viewstate
    >> > in the described scenario or will I have to do some kind of convoluted
    >> > CustomValidation where I check the Request collection? Based upon the

    > FAQ
    >> > below, I am assuming that converting to web controls wouldn't solve the
    >> > problem either - this seems to be a client vs server side issue with
    >> > regard
    >> > to how the validation works.
    >> >
    >> > Brian
    >> >
    >> > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    >> > wrote in message news:uP$6M$...
    >> >> I wouldn't expect server-side validation to work on client-side added
    >> > items.
    >> >>
    >> >> Take a look at: http://openmymind.net/FAQ.aspx?documentId=1
    >> >>
    >> >> but the quick answer is that when you add items in javascript, they
    >> >> aren't
    >> >> added to the viewstate which means they won't be recreated on
    >> >> postback...explains why your htmlselect is empty...
    >> >>
    >> >> Karl
    >> >>
    >> >>
    >> >> --
    >> >> MY ASP.Net tutorials
    >> >> http://www.openmymind.net/ - New and Improved (yes, the popup is
    >> >> annoying)
    >> >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    >> >> come!)
    >> >>
    >> >>
    >> >> "BK" <> wrote in message
    >> >> news:...
    >> >> > I'm having a really strange problem with and HtmlSelect server

    > control
    >> >> > (listbox) and a RequiredFieldValidator that I am trying to use to

    > make
    >> >> > sure
    >> >> > that someone has items in the listbox.
    >> >> >
    >> >> > The way that the HtmlSelect is populated is via a combination of
    >> >> > client-side
    >> >> > javascript and another aspx page (launched by the javascript).
    >> >> >
    >> >> > Anyway, everything seems to work just fine in terms of populating
    >> >> > the
    >> >> > HtmlSelect. However, when I postback the form, the
    >> > RequiredFieldValidator
    >> >> > always thinks that there is nothing in the HtmlSelect and fails
    >> > validation
    >> >> > (I am only using server-side validation, by the way). I have the
    >> >> > ControlToValidate and all those things hooked up properly. Is there
    >> >> > some
    >> >> > trick to setting the RequiredFieldValidator for an HtmlSelect

    > control?
    >> >> > Some
    >> >> > property that I am not setting?? I suspect that there is some small
    >> >> > setting
    >> >> > that I am missing, but I have spent way too much time on this to
    >> >> > keep
    >> >> > struggling.
    >> >> >
    >> >> > Any help is appreciated,
    >> >> > Thanks
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
     
    Karl Seguin, May 4, 2005
    #10
  11. BK

    BK Guest

    There is a requirement to use the validation controls (if possible, I
    guess). And, there is a common page structure that does the standard
    Page.Validate and Page.IsValid. So, it would be preferrable to have these
    evaluate properly. Is there not a page event that I can override, load the
    HtmlSelect with the values in the hdnValues field and expect the validators
    to work?

    If I am understanding you correctly, you are suggesting that I simply write
    a function to see if something is there. If my purpose were simply to know
    if something had been entered that would be a fine solution, but what I am
    really trying to do is understand how I fit this within the context of using
    the server-side validation controls (requiredfieldvalidator), since that is
    the architecture that has been laid out.

    If the server-side validation is driving off of viewstate, isn't there a
    page event somewhere during the postback that I can modify the viewstate so
    that the requiredfieldvalidator sees that the HtmlSelect is no longer
    empty???

    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:%...
    > The information will be available in the Page_Load event. It's loaded in
    > the LoadPostbackData event of the individual contorl - not the pages.
    >
    > Why not just write your own validation event....By the time you get to a
    > bottom's click event, the data is there, write a function

    "IsCustomValide()"
    > which checks to see if hdnValues has a value?
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    > "BK" <> wrote in message
    > news:...
    > > I'm still having trouble with this, here is what I have done (I'm not
    > > using
    > > client-side validation, by the way - customer requirement):
    > >
    > > 1) As I mentioned before, everything works fine client-side in terms of
    > > items being added to the HtmlSelect control. I get a nice list of items

    in
    > > my form, as expected. In addition, I have a hidden input field that

    holds
    > > a
    > > string representation of the values, so that I can persist between
    > > postbacks. For the sake of argument, lets call my HtmlSelect (which is
    > > runat=server) "lstValues" and my hidden input (which is also

    runat=server)
    > > "hdnValues".
    > >
    > > 2) Now, from what I understand, I should be able to truly populate the
    > > HtmlSelect control (as .NET sees it) on the server-side, so that when
    > > validation rolls around in the page event cycle, it will see that items
    > > have
    > > been added. This is where confusion sets in.
    > >
    > > 3) It seems that Page_Init is too early to set any values because
    > > "hdnValues" is always an empty string. So, that doesn't work.
    > >
    > > 4) I have tried adding IPostbackDataHandler to my page and implementing
    > > LoadPostbackData, but this doesn't seem to work. The values are set, but
    > > the
    > > validation still fails.
    > >
    > > 5) I have tried adding multiple other events that supposedly occur

    before
    > > validation and populating lstValues there, but all to no avail.

    Validation
    > > still fails.
    > >
    > > 6) I have googled and read everything that I can find, but nothing seem

    to
    > > work.
    > >
    > > This cannot be this difficult. I feel like I have all that I need on the
    > > client-side, I just need to know what to do and where to do it in the
    > > code-behind in order to catch the page event before validation and
    > > populate
    > > lstValues with the items that I have. Also, from what I understand (and

    I
    > > have observed the problem, so I know its true) CustomValidators don't

    work
    > > with HtmlSelect - the event doesn't fire, so that is not an option

    either.
    > >
    > > Any help is appreciated, I have been working on this all day....
    > >
    > > TIA
    > > BK
    > >
    > > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    > > wrote in message news:OtuCBM$...
    > >> You are pretty much right about everything. Though I would expect the
    > >> client-side validation to still work (not necessarily ideal since it

    only
    > >> works in IE...)
    > >>
    > >> -items need to be added server-side
    > >> -going to dropdownlist (server control) wouldn't change anything
    > >> -you'll need to write your own validator and use request.form
    > >>
    > >> Cheers,
    > >> Karl
    > >>
    > >> --
    > >> MY ASP.Net tutorials
    > >> http://www.openmymind.net/ - New and Improved (yes, the popup is
    > >> annoying)
    > >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > >> come!)
    > >> "BK" <> wrote in message
    > >> news:O3Fu5l%...
    > >> > OK, this sort of makes sense to me. But, all the documentation that I

    > > have
    > >> > read says that the RequiredFieldValidator works with an HtmlSelect

    > > server
    > >> > control. I guess what you are saying is that the items need to be

    added
    > >> > server-side for this to work?
    > >> >
    > >> > Also, if this is the case, then is there a way to add them to the
    > >> > viewstate
    > >> > in the described scenario or will I have to do some kind of

    convoluted
    > >> > CustomValidation where I check the Request collection? Based upon the

    > > FAQ
    > >> > below, I am assuming that converting to web controls wouldn't solve

    the
    > >> > problem either - this seems to be a client vs server side issue with
    > >> > regard
    > >> > to how the validation works.
    > >> >
    > >> > Brian
    > >> >
    > >> > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME

    net>
    > >> > wrote in message news:uP$6M$...
    > >> >> I wouldn't expect server-side validation to work on client-side

    added
    > >> > items.
    > >> >>
    > >> >> Take a look at: http://openmymind.net/FAQ.aspx?documentId=1
    > >> >>
    > >> >> but the quick answer is that when you add items in javascript, they
    > >> >> aren't
    > >> >> added to the viewstate which means they won't be recreated on
    > >> >> postback...explains why your htmlselect is empty...
    > >> >>
    > >> >> Karl
    > >> >>
    > >> >>
    > >> >> --
    > >> >> MY ASP.Net tutorials
    > >> >> http://www.openmymind.net/ - New and Improved (yes, the popup is
    > >> >> annoying)
    > >> >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more

    to
    > >> >> come!)
    > >> >>
    > >> >>
    > >> >> "BK" <> wrote in message
    > >> >> news:...
    > >> >> > I'm having a really strange problem with and HtmlSelect server

    > > control
    > >> >> > (listbox) and a RequiredFieldValidator that I am trying to use to

    > > make
    > >> >> > sure
    > >> >> > that someone has items in the listbox.
    > >> >> >
    > >> >> > The way that the HtmlSelect is populated is via a combination of
    > >> >> > client-side
    > >> >> > javascript and another aspx page (launched by the javascript).
    > >> >> >
    > >> >> > Anyway, everything seems to work just fine in terms of populating
    > >> >> > the
    > >> >> > HtmlSelect. However, when I postback the form, the
    > >> > RequiredFieldValidator
    > >> >> > always thinks that there is nothing in the HtmlSelect and fails
    > >> > validation
    > >> >> > (I am only using server-side validation, by the way). I have the
    > >> >> > ControlToValidate and all those things hooked up properly. Is

    there
    > >> >> > some
    > >> >> > trick to setting the RequiredFieldValidator for an HtmlSelect

    > > control?
    > >> >> > Some
    > >> >> > property that I am not setting?? I suspect that there is some

    small
    > >> >> > setting
    > >> >> > that I am missing, but I have spent way too much time on this to
    > >> >> > keep
    > >> >> > struggling.
    > >> >> >
    > >> >> > Any help is appreciated,
    > >> >> > Thanks
    > >> >> >
    > >> >> >
    > >> >>
    > >> >>
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
     
    BK, May 4, 2005
    #11
    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. Suhail A, Salman
    Replies:
    0
    Views:
    353
    Suhail A, Salman
    Aug 13, 2003
  2. Suhail A, Salman
    Replies:
    1
    Views:
    3,666
  3. nospam
    Replies:
    4
    Views:
    2,775
    nospam
    Oct 16, 2003
  4. xenophon

    HtmlSelect and PostBack?

    xenophon, Mar 7, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,911
    Sylvain Lafontaine
    Mar 7, 2005
  5. Harry Keck
    Replies:
    0
    Views:
    241
    Harry Keck
    Jan 27, 2005
Loading...

Share This Page