CustomValidator is hidden

Discussion in 'ASP .Net Web Controls' started by David Thielen, May 16, 2006.

  1. Hi;

    I have a CustomValidator that is always drawn hidden. I have tried setting
    Visible to true in the aspx and aspx.cs files - and it is still hidden. Any
    ideas?

    --
    thanks - dave
    david_at_windward_dot_net
    http://www.windwardreports.com
     
    David Thielen, May 16, 2006
    #1
    1. Advertising

  2. ps - this is inside a Repeater/ItemTemplate

    --
    thanks - dave
    david_at_windward_dot_net
    http://www.windwardreports.com



    "David Thielen" wrote:

    > Hi;
    >
    > I have a CustomValidator that is always drawn hidden. I have tried setting
    > Visible to true in the aspx and aspx.cs files - and it is still hidden. Any
    > ideas?
    >
    > --
    > thanks - dave
    > david_at_windward_dot_net
    > http://www.windwardreports.com
    >
     
    David Thielen, May 16, 2006
    #2
    1. Advertising

  3. Hi Dave,

    Thank you for posting.

    As for the Custom Validator displaying issue, I think it is mostly a page
    specific issue. What's the detailed code/aspx template of that repeater
    page? As for custom validator, it will display only when there is
    validation error get triggered. Also, are you using client-side validation
    or server-side validation?

    Regards,

    Steven Cheng
    Microsoft Online Community Support


    ==================================================

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], May 16, 2006
    #3
  4. Here you go - all server side:

    aspx code:
    <asp:Repeater ID="mapRows" runat="server" OnDataBinding="MapBinding"
    OnItemDataBound="MapDataBound">
    <HeaderTemplate>
    <tr>
    <th colspan='3'>
    Report parameters</th>
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
    <td>
    <asp:Label ID="mapName" runat="server"
    Text='<%#Eval("Name")%>'></asp:Label>
    </td>
    <td>
    <asp:TextBox ID="mapTextValue" runat="server"
    Columns="60"></asp:TextBox>
    <asp:CustomValidator ID="mapValidator" runat="server"
    ErrorMessage="CustomValidator"
    ControlToValidate="mapTextValue">yyy</asp:CustomValidator>
    <asp:Calendar ID="mapCalendarValue" runat="server"
    Visible="false"></asp:Calendar>
    <asp:DropDownList ID="mapListValue" runat="server"
    Visible="false"></asp:DropDownList>
    </td>
    </tr>
    </ItemTemplate>
    </asp:Repeater>


    cs code:
    string key = ((Label)ri.FindControl("mapName")).Text;
    CustomValidator validator = (CustomValidator)ri.FindControl("mapValidator");
    validator.Text = "Please enter a value for the map var " + key;
    validator.IsValid = false;

    It sets the text but the field is hidden.

    Any ideas?

    thanks - dave
     
    David Thielen, May 25, 2006
    #4
  5. Hi Dave,

    Thanks for your response.

    From the code snippet you provided, you define the customvalidator with the
    following control template:

    =================
    <asp:CustomValidator ID="mapValidator" runat="server"
    ErrorMessage="CustomValidator"
    ControlToValidate="mapTextValue">yyy</asp:CustomValidator>
    ================

    I think the problem here is that you didn't provide a Server-side
    validation handler(or client-side validate function) for the custom valiate
    control. Also, the error message of Validator control will only display
    when the validation occurs(and there is validation error). BTW, custom
    validation won't occur when the validating control's Field(such as Text
    property is empty).

    As for how to write a servervalidation handler, you can reference to the
    following msdn document:

    #ServerValidateEventHandler Delegate
    http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiwebcontro
    lsservervalidateeventhandlerclasstopic.asp?frame=true

    Hope this helps.

    Regards,

    Steven Cheng
    Microsoft Online Community Support


    ==================================================

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], May 26, 2006
    #5
  6. Hi;

    Ok, I have it working that way but a couple of things don't make sense.

    1) When I click on a button, first it calls the server validation method,
    then it calls the button click handler even though the validation method
    returned false, then it calls the validation method a second time. So I have
    to validate in the button click handler too which makes no sense.

    2) I do not have to have an OnServerValidate for any of my other
    CustomValidators - just for the one I have inside the Repeater control.

    3) It has the validator in the html creates - it's just that it is marked
    hidden.

    --
    thanks - dave
    david_at_windward_dot_net
    http://www.windwardreports.com



    "Steven Cheng[MSFT]" wrote:

    > Hi Dave,
    >
    > Thanks for your response.
    >
    > From the code snippet you provided, you define the customvalidator with the
    > following control template:
    >
    > =================
    > <asp:CustomValidator ID="mapValidator" runat="server"
    > ErrorMessage="CustomValidator"
    > ControlToValidate="mapTextValue">yyy</asp:CustomValidator>
    > ================
    >
    > I think the problem here is that you didn't provide a Server-side
    > validation handler(or client-side validate function) for the custom valiate
    > control. Also, the error message of Validator control will only display
    > when the validation occurs(and there is validation error). BTW, custom
    > validation won't occur when the validating control's Field(such as Text
    > property is empty).
    >
    > As for how to write a servervalidation handler, you can reference to the
    > following msdn document:
    >
    > #ServerValidateEventHandler Delegate
    > http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiwebcontro
    > lsservervalidateeventhandlerclasstopic.asp?frame=true
    >
    > Hope this helps.
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Community Support
    >
    >
    > ==================================================
    >
    > When responding to posts, please "Reply to Group" via your newsreader so
    > that others may learn and benefit from your issue.
    >
    > ==================================================
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
    >
    >
    >
     
    David Thielen, May 27, 2006
    #6
  7. Hi Dave,

    Here is my understanding inline:

    1) When I click on a button, first it calls the server validation method,
    then it calls the button click handler even though the validation method
    returned false, then it calls the validation method a second time. So I
    have
    to validate in the button click handler too which makes no sense.
    ================================
    As for Validation control, when we use server-side validation, the
    Validation function of the validators are called after Page Load event, but
    before processing postback events. Thus, we can use the Page.IsValid or
    ValidatorControl's "IsValid" property determine whether the validation is
    passed and our code logic in postback event should also change depend on
    this detection.


    2) I do not have to have an OnServerValidate for any of my other
    CustomValidators - just for the one I have inside the Repeater control.
    ===============================
    Which one(Row) is the one you want to make the validation control enable
    validating? I think you can consider using the "ItemCreated" event of
    Repeater control to customize certain control in the repeaterItem. Also,
    you can consider using DataList control and put your particular validation
    control only in the EditTemplate so that only the current Row being edited
    will contains the validator control.


    3) It has the validator in the html creates - it's just that it is marked
    hidden.
    =================================
    I'm still not quite clear on this. Why would you configure the validator to
    be invislbe?

    Here are some msdn reference on using validation controls in ASP.NET 2.0:

    #Learning More ¡ª Validation Controls
    http://msdn2.microsoft.com/en-us/library/ms178317.aspx

    Regards,

    Steven Cheng
    Microsoft Online Community Support


    ==================================================

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], May 29, 2006
    #7
    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. Edmilson

    Errormessage in CustomValidator

    Edmilson, Jul 10, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    399
    Edmilson
    Jul 10, 2003
  2. Wayne MJ

    CustomValidator limitation?

    Wayne MJ, Jul 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    360
    Wayne MJ
    Jul 21, 2003
  3. George Ter-Saakov

    CustomValidator controls

    George Ter-Saakov, Jul 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    390
    George Ter-Saakov
    Jul 21, 2003
  4. Rick
    Replies:
    3
    Views:
    8,571
    Alexey Smirnov
    Apr 13, 2010
  5. SolarCanine
    Replies:
    2
    Views:
    338
    SolarCanine
    Sep 20, 2005
Loading...

Share This Page