Login Control/Validation Summary within Content Placeholder

Discussion in 'ASP .Net' started by ilockett, Feb 27, 2006.

  1. ilockett

    ilockett Guest

    The background:
    I have a web app with a simple master page that contains just one
    content placeholder.

    I have created a web form that then uses this master page. Within the
    content placeholder, I have placed a Login control (Login1) and a
    ValidationSummary control.

    I have set the ValidationSummary's ValidationGroup property equal to
    "Login1".

    The problem:
    The validation summary is not firing when a login textbox is left
    blank.

    What I have found:
    I put the Login control and ValidationSummary control in a separate
    page that uses no masterpage/content placeholders - and it works fine.
    So it seems the issue begins with the master page/content involvement.

    I looked at the HTML source on both pages and this throws up what I
    think is causing the problem - but I'm not sure how to resolve it!

    In the non-master page file, you get the following markup:

    <script type="text/javascript">
    <!--
    var Login1_UserNameRequired = document.all ?
    document.all["Login1_UserNameRequired"] :
    document.getElementById("Login1_UserNameRequired");
    Login1_UserNameRequired.controltovalidate = "Login1_UserName";
    Login1_UserNameRequired.errormessage = "User Name is required.";
    Login1_UserNameRequired.validationGroup = "Login1";
    Login1_UserNameRequired.evaluationfunction =
    "RequiredFieldValidatorEvaluateIsValid";
    Login1_UserNameRequired.initialvalue = "";
    var Login1_PasswordRequired = document.all ?
    document.all["Login1_PasswordRequired"] :
    document.getElementById("Login1_PasswordRequired");
    Login1_PasswordRequired.controltovalidate = "Login1_Password";
    Login1_PasswordRequired.errormessage = "Password is required.";
    Login1_PasswordRequired.validationGroup = "Login1";
    Login1_PasswordRequired.evaluationfunction =
    "RequiredFieldValidatorEvaluateIsValid";
    Login1_PasswordRequired.initialvalue = "";
    var ValidationSummary1 = document.all ?
    document.all["ValidationSummary1"] :
    document.getElementById("ValidationSummary1");
    ValidationSummary1.validationGroup = "Login1";
    // -->
    </script>

    However, when I use the master page code, you get:

    <script type="text/javascript">
    <!--
    var ctl00_ContentPlaceHolder1_Login1_UserNameRequired = document.all ?
    document.all["ctl00_ContentPlaceHolder1_Login1_UserNameRequired"] :
    document.getElementById("ctl00_ContentPlaceHolder1_Login1_UserNameRequired");
    ctl00_ContentPlaceHolder1_Login1_UserNameRequired.controltovalidate =
    "ctl00_ContentPlaceHolder1_Login1_UserName";
    ctl00_ContentPlaceHolder1_Login1_UserNameRequired.errormessage = "User
    Name is required.";
    ctl00_ContentPlaceHolder1_Login1_UserNameRequired.validationGroup =
    "ctl00$ContentPlaceHolder1$Login1";
    ctl00_ContentPlaceHolder1_Login1_UserNameRequired.evaluationfunction =
    "RequiredFieldValidatorEvaluateIsValid";
    ctl00_ContentPlaceHolder1_Login1_UserNameRequired.initialvalue = "";
    var ctl00_ContentPlaceHolder1_Login1_PasswordRequired = document.all ?
    document.all["ctl00_ContentPlaceHolder1_Login1_PasswordRequired"] :
    document.getElementById("ctl00_ContentPlaceHolder1_Login1_PasswordRequired");
    ctl00_ContentPlaceHolder1_Login1_PasswordRequired.controltovalidate =
    "ctl00_ContentPlaceHolder1_Login1_Password";
    ctl00_ContentPlaceHolder1_Login1_PasswordRequired.errormessage =
    "Password is required.";
    ctl00_ContentPlaceHolder1_Login1_PasswordRequired.validationGroup =
    "ctl00$ContentPlaceHolder1$Login1";
    ctl00_ContentPlaceHolder1_Login1_PasswordRequired.evaluationfunction =
    "RequiredFieldValidatorEvaluateIsValid";
    ctl00_ContentPlaceHolder1_Login1_PasswordRequired.initialvalue = "";
    var ctl00_ContentPlaceHolder1_ValidationSummary1 = document.all ?
    document.all["ctl00_ContentPlaceHolder1_ValidationSummary1"] :
    document.getElementById("ctl00_ContentPlaceHolder1_ValidationSummary1");
    ctl00_ContentPlaceHolder1_ValidationSummary1.validationGroup =
    "ContentPlaceHolder1.Login1";
    // -->
    </script>

    It seems that the ValidationGroup for the internal controls of the
    Login control has been changed from "Login1" to
    "ctl00$ContentPlaceHolder1$Login1" causing a mis-match between the
    Login control and ValidationSummary.

    Is there a way of rectifying this?

    Many thanks in hope of a reply!!

    Ian
     
    ilockett, Feb 27, 2006
    #1
    1. Advertising

  2. ilockett,
    Error you are adding validation to the login control that does its own
    validation. You have your design backwards or are doing something wrong.

    Good Luck finding your error.
    DWS



    "ilockett" wrote:

    > The background:
    > I have a web app with a simple master page that contains just one
    > content placeholder.
    >
    > I have created a web form that then uses this master page. Within the
    > content placeholder, I have placed a Login control (Login1) and a
    > ValidationSummary control.
    >
    > I have set the ValidationSummary's ValidationGroup property equal to
    > "Login1".
    >
    > The problem:
    > The validation summary is not firing when a login textbox is left
    > blank.
    >
    > What I have found:
    > I put the Login control and ValidationSummary control in a separate
    > page that uses no masterpage/content placeholders - and it works fine.
    > So it seems the issue begins with the master page/content involvement.
    >
    > I looked at the HTML source on both pages and this throws up what I
    > think is causing the problem - but I'm not sure how to resolve it!
    >
    > In the non-master page file, you get the following markup:
    >
    > <script type="text/javascript">
    > <!--
    > var Login1_UserNameRequired = document.all ?
    > document.all["Login1_UserNameRequired"] :
    > document.getElementById("Login1_UserNameRequired");
    > Login1_UserNameRequired.controltovalidate = "Login1_UserName";
    > Login1_UserNameRequired.errormessage = "User Name is required.";
    > Login1_UserNameRequired.validationGroup = "Login1";
    > Login1_UserNameRequired.evaluationfunction =
    > "RequiredFieldValidatorEvaluateIsValid";
    > Login1_UserNameRequired.initialvalue = "";
    > var Login1_PasswordRequired = document.all ?
    > document.all["Login1_PasswordRequired"] :
    > document.getElementById("Login1_PasswordRequired");
    > Login1_PasswordRequired.controltovalidate = "Login1_Password";
    > Login1_PasswordRequired.errormessage = "Password is required.";
    > Login1_PasswordRequired.validationGroup = "Login1";
    > Login1_PasswordRequired.evaluationfunction =
    > "RequiredFieldValidatorEvaluateIsValid";
    > Login1_PasswordRequired.initialvalue = "";
    > var ValidationSummary1 = document.all ?
    > document.all["ValidationSummary1"] :
    > document.getElementById("ValidationSummary1");
    > ValidationSummary1.validationGroup = "Login1";
    > // -->
    > </script>
    >
    > However, when I use the master page code, you get:
    >
    > <script type="text/javascript">
    > <!--
    > var ctl00_ContentPlaceHolder1_Login1_UserNameRequired = document.all ?
    > document.all["ctl00_ContentPlaceHolder1_Login1_UserNameRequired"] :
    > document.getElementById("ctl00_ContentPlaceHolder1_Login1_UserNameRequired");
    > ctl00_ContentPlaceHolder1_Login1_UserNameRequired.controltovalidate =
    > "ctl00_ContentPlaceHolder1_Login1_UserName";
    > ctl00_ContentPlaceHolder1_Login1_UserNameRequired.errormessage = "User
    > Name is required.";
    > ctl00_ContentPlaceHolder1_Login1_UserNameRequired.validationGroup =
    > "ctl00$ContentPlaceHolder1$Login1";
    > ctl00_ContentPlaceHolder1_Login1_UserNameRequired.evaluationfunction =
    > "RequiredFieldValidatorEvaluateIsValid";
    > ctl00_ContentPlaceHolder1_Login1_UserNameRequired.initialvalue = "";
    > var ctl00_ContentPlaceHolder1_Login1_PasswordRequired = document.all ?
    > document.all["ctl00_ContentPlaceHolder1_Login1_PasswordRequired"] :
    > document.getElementById("ctl00_ContentPlaceHolder1_Login1_PasswordRequired");
    > ctl00_ContentPlaceHolder1_Login1_PasswordRequired.controltovalidate =
    > "ctl00_ContentPlaceHolder1_Login1_Password";
    > ctl00_ContentPlaceHolder1_Login1_PasswordRequired.errormessage =
    > "Password is required.";
    > ctl00_ContentPlaceHolder1_Login1_PasswordRequired.validationGroup =
    > "ctl00$ContentPlaceHolder1$Login1";
    > ctl00_ContentPlaceHolder1_Login1_PasswordRequired.evaluationfunction =
    > "RequiredFieldValidatorEvaluateIsValid";
    > ctl00_ContentPlaceHolder1_Login1_PasswordRequired.initialvalue = "";
    > var ctl00_ContentPlaceHolder1_ValidationSummary1 = document.all ?
    > document.all["ctl00_ContentPlaceHolder1_ValidationSummary1"] :
    > document.getElementById("ctl00_ContentPlaceHolder1_ValidationSummary1");
    > ctl00_ContentPlaceHolder1_ValidationSummary1.validationGroup =
    > "ContentPlaceHolder1.Login1";
    > // -->
    > </script>
    >
    > It seems that the ValidationGroup for the internal controls of the
    > Login control has been changed from "Login1" to
    > "ctl00$ContentPlaceHolder1$Login1" causing a mis-match between the
    > Login control and ValidationSummary.
    >
    > Is there a way of rectifying this?
    >
    > Many thanks in hope of a reply!!
    >
    > Ian
    >
    >
     
    =?Utf-8?B?RFdT?=, Mar 1, 2006
    #2
    1. Advertising

  3. ilockett

    ilockett Guest

    DWS

    Thanks for taking the time to reply.

    Whilst the Login control does have it's own validation - it only
    displays the asterisk after the textbox and does not actually display a
    message. This could be missed by some users.

    I was hoping that the validation summary would show the error in a more
    explicit way. I don't feel I am doing anything wrong - the
    combination of Login and ValidationSummary works fine when not used
    within a Content Placeholder.

    I have so far worked around it by using the FindControl method:

    Dim myLogin As Login
    Dim mySummary As ValidationSummary
    myLogin =
    [LoginViewControlName].FindControl("[LoginControlName]")
    mySummary =
    [LoginViewControlName].FindControl("[ValidationSummaryControlName")
    If myLogin IsNot Nothing Then
    ' Replace the returned underscores with dollar signs.
    mySummary.ValidationGroup = Replace(myLogin.ClientID, "_",
    "$")
    End If

    However, I'm really not happy in having to do it this way, and so any
    other suggestions are more than welcome.

    Many thanks
    Ian
     
    ilockett, Mar 1, 2006
    #3
  4. Ian,

    I was having the same problem last night. It frustrated me for a good two
    hours and I still have no fix. Glad to see that it's a problem with the
    Master Pages, that was what I was going to try to test this time around... I
    will probably end up using your workaround for now. If I come up with
    something else I will let you know.

    Dan

    "ilockett" wrote:

    > DWS
    >
    > Thanks for taking the time to reply.
    >
    > Whilst the Login control does have it's own validation - it only
    > displays the asterisk after the textbox and does not actually display a
    > message. This could be missed by some users.
    >
    > I was hoping that the validation summary would show the error in a more
    > explicit way. I don't feel I am doing anything wrong - the
    > combination of Login and ValidationSummary works fine when not used
    > within a Content Placeholder.
    >
    > I have so far worked around it by using the FindControl method:
    >
    > Dim myLogin As Login
    > Dim mySummary As ValidationSummary
    > myLogin =
    > [LoginViewControlName].FindControl("[LoginControlName]")
    > mySummary =
    > [LoginViewControlName].FindControl("[ValidationSummaryControlName")
    > If myLogin IsNot Nothing Then
    > ' Replace the returned underscores with dollar signs.
    > mySummary.ValidationGroup = Replace(myLogin.ClientID, "_",
    > "$")
    > End If
    >
    > However, I'm really not happy in having to do it this way, and so any
    > other suggestions are more than welcome.
    >
    > Many thanks
    > Ian
    >
    >
     
    =?Utf-8?B?RGFuIERvbm92YW4=?=, Apr 20, 2006
    #4
    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. John
    Replies:
    1
    Views:
    371
    zPaul
    Jul 1, 2003
  2. Lucas Tam
    Replies:
    2
    Views:
    1,115
    Lucas Tam
    Feb 26, 2004
  3. =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=

    Using Summary Validation control with server Custom validation

    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=, Oct 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    884
    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=
    Oct 15, 2004
  4. John
    Replies:
    2
    Views:
    914
  5. nail

    Build control in a placeholder or like a placeholder

    nail, Sep 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    345
Loading...

Share This Page