Client Validation Javascript not rendering

Discussion in 'ASP .Net' started by =?Utf-8?B?Rm91cmdl?=, Jan 25, 2005.

  1. Hi,
    I have run into a very strange scenario. In developing an ASP.NET
    application on framework version 1.1, I found that certain client-side
    validation scripts were not being rendered. The reason we came up with for
    this was because we had a PageBase base class for all our pages. This base
    class takes the controls on the child page class and places them onto the
    form being rendered. It seems that in this process, the rendering of the
    validation calls gets lost. To overcome this problem I added code to add the
    required client-side function call on the "onclick" event of the necessary
    buttons as follows:

    <input type="submit" name="btnSave" value="Save" onclick="btnClose.enabled =
    'false';if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();
    if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); "
    language="javascript" id="btnSave" class="button" style="width:68px;" />

    Can anybody tell me if the original problem was a bug in the framework, IIS5
    etc.? Also, if it was a framework bug, why does it differ with the same
    version on WinXP Pro and Win2003 Server?

    Any light on this subject will be greatly appreciated.

    Fourge
    btnSubmit.Attributes.Add("onclick","btnClose.enabled = 'false';if
    (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); ");

    After adding this, it worked great in our development and test environment.
    Our development is done on Windows XP Pro with IIS5 and our testing on
    Windows 2000 Server with IIS5. Both environments running .NET Framework 1.1.

    One of the deployments we did was into the Windows 2003 Server environment.
    Once th application was running in that environment, we found that the
    validation function calls above were now being added and so we were getting
    the javascript calls twice in the rendered html page as follows:
    =?Utf-8?B?Rm91cmdl?=, Jan 25, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Rm91cmdl?=

    Peter Blum Guest

    While there is a bug in client-side validation in ASP.NET 1.1 SP1, I don't
    think it is involved here. That bug prevents the button click from ever
    submitting the page. See
    http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=739537

    If the button is not generating its onclick event code, there are two
    possible reasons:
    1. CausesValidation is false on the button.
    2. The Page.Validators collection has no validators (or perhaps just
    "active" validators where their Visible property is true.)

    I don't know how your code moves controls around and wonder if it ends up
    clobbering the Page.Validators collection.

    --- Peter Blum
    www.PeterBlum.com
    Email:
    Creator of "Professional Validation And More" at
    http://www.peterblum.com/vam/home.aspx

    "Fourge" <> wrote in message
    news:...
    > Hi,
    > I have run into a very strange scenario. In developing an ASP.NET
    > application on framework version 1.1, I found that certain client-side
    > validation scripts were not being rendered. The reason we came up with
    > for
    > this was because we had a PageBase base class for all our pages. This
    > base
    > class takes the controls on the child page class and places them onto the
    > form being rendered. It seems that in this process, the rendering of the
    > validation calls gets lost. To overcome this problem I added code to add
    > the
    > required client-side function call on the "onclick" event of the necessary
    > buttons as follows:
    >
    > <input type="submit" name="btnSave" value="Save" onclick="btnClose.enabled
    > =
    > 'false';if (typeof(Page_ClientValidate) == 'function')
    > Page_ClientValidate();
    > if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); "
    > language="javascript" id="btnSave" class="button" style="width:68px;" />
    >
    > Can anybody tell me if the original problem was a bug in the framework,
    > IIS5
    > etc.? Also, if it was a framework bug, why does it differ with the same
    > version on WinXP Pro and Win2003 Server?
    >
    > Any light on this subject will be greatly appreciated.
    >
    > Fourge
    > btnSubmit.Attributes.Add("onclick","btnClose.enabled = 'false';if
    > (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); ");
    >
    > After adding this, it worked great in our development and test
    > environment.
    > Our development is done on Windows XP Pro with IIS5 and our testing on
    > Windows 2000 Server with IIS5. Both environments running .NET Framework
    > 1.1.
    >
    > One of the deployments we did was into the Windows 2003 Server
    > environment.
    > Once th application was running in that environment, we found that the
    > validation function calls above were now being added and so we were
    > getting
    > the javascript calls twice in the rendered html page as follows:
    Peter Blum, Jan 25, 2005
    #2
    1. Advertising

  3. Hi Fourge,

    I'm also a bit interested in how your base pages adding those validation
    controls. As far as I knew, the validation control will regsiter the
    clientside script in their OnPrender event. So if we adding the validtion
    controls correctly before Prerender, that should not be the problem.

    I think we can first check whether the output page is correctly emiting the
    validation's required script in page output and whether the script files on
    the deployment server is correctly installed. As you mentioned that when
    you're using the base page to adding those validation controls and the
    validtion not work, have you tried viewing the page's output html code at
    the clientside (via View source). You can have a look whether the script
    codes are embeded correctly. If the code is correctly there, we may have a
    check on the server's asp.net clientside script installation. Try
    executing the
    aspnet_regiis -c
    command to reinstall the asp.net common script files on the server and test
    again to see whether it works.

    Anyway, I think it'll be better to start test from a simple page with a
    textbox and a validtion control.

    If there is any other findings, please feel free to post here. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Jan 26, 2005
    #3
  4. =?Utf-8?B?Rm91cmdl?=

    vitorrubio

    Joined:
    Jul 21, 2010
    Messages:
    1
    Service Pack Version?

    I had the same problem, and I trying to access a simple page with only one TextBox, one RequiredFieldValidator and one button.

    I'm using .Net framework 1.1 and visual studio 2003

    I have three servers: one with windows XP sp2 (development) and other two with Windows 2003 server and IIS 6.
    The client - code rendered by the Win xp machine works, and the client validation works fine, but the code rendered by the win 2003 machine doesn't work.
    Below the codes:


    working code ...

    HTML:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
      ...
    
      <body MS_POSITIONING="GridLayout">
    	
        <form method="post" action="teste.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="Form1">
    <div class="aspNetHidden">
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTcyMzUyODc3OWRkgRhvsR5UK3vvocXrO1qomevAnDqvQLEIr9xosJzc144=" />
    </div>
    
    <script type="text/javascript">
    //<![CDATA[
    var theForm = document.forms['Form1'];
    if (!theForm) {
        theForm = document.Form1;
    }
    function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    //]]>
    </script>
    
    
    <s c r i p t s r c="/VendasPortal/WebResource.axd?d=Y9yRm5JYEUG0635f1BSfHg2&amp;t=634109895716662567" type="text/javascript"></script>
    
    [B]<script src="/VendasPortal/WebResource.axd?d=DmxOgWmpaO0fHDXSwAhjW05EVUsM6EimrZSGOo1mVPk1&amp;t=634109895716662567" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    function WebForm_OnSubmit() {
    if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
    return true;
    }
    //]]>
    </script>[/B]
    
    <div class="aspNetHidden">
    
    	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLCiPquAgLs0bLrBgKM54rGBhzafW1C+OfPIJPDNNAdnRbXCW+QuT0S6TfTUi17hdWP" />
    </div><input name="TextBox1" type="text" id="TextBox1" style="Z-INDEX: 101; POSITION: absolute; TOP: 56px; LEFT: 264px" /><input type="submit" name="Button1" value="Button" onclick="[B]javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;Button1&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))[/B]" id="Button1" style="Z-INDEX: 102; POSITION: absolute; TOP: 112px; LEFT: 264px" /><span id="RequiredFieldValidator1" style="Z-INDEX:103;POSITION:absolute;TOP:56px;LEFT:440px;visibility:hidden;">RequiredFieldValidator</span><div id="ValidationSummary1" style="Z-INDEX:104;POSITION:absolute;TOP:104px;LEFT:384px;display:none;">
    
    </div>
    
         
    <script type="text/javascript">
    //<![CDATA[
    var Page_ValidationSummaries =  new Array(document.getElementById("ValidationSummary1"));
    var Page_Validators =  new Array(document.getElementById("RequiredFieldValidator1"));
    //]]>
    
    </script>
    
    [B]<script type="text/javascript">
    //<![CDATA[
    var RequiredFieldValidator1 = document.all ? document.all["RequiredFieldValidator1"] : document.getElementById("RequiredFieldValidator1");
    RequiredFieldValidator1.controltovalidate = "TextBox1";
    RequiredFieldValidator1.errormessage = "RequiredFieldValidator";
    RequiredFieldValidator1.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
    RequiredFieldValidator1.initialvalue = "";
    var ValidationSummary1 = document.all ? document.all["ValidationSummary1"] : document.getElementById("ValidationSummary1");
    ValidationSummary1.showmessagebox = "True";
    //]]>
    </script>[/B]
    
    
    <script type="text/javascript">
    //<![CDATA[
    
    var Page_ValidationActive = false;
    if (typeof(ValidatorOnLoad) == "function") {
        ValidatorOnLoad();
    }
    
    function ValidatorOnSubmit() {
        if (Page_ValidationActive) {
            return ValidatorCommonOnSubmit();
        }
        else {
            return true;
        }
    }
            //]]>
    </script>
    </form>
    	
      </body>
    </HTML>
    
    the non-working code:
    HTML:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
     ...
    
      <body MS_POSITIONING="GridLayout">
    	
        <form name="Form1" method="post" action="teste.aspx" id="Form1">
    <input type="hidden" name="__VIEWSTATE" value="dDwyNTc1Nzk2ODE7Oz5ZXN65Bn54k9P6APUWZPmu+eMTUw==" />
    <input name="TextBox1" type="text" id="TextBox1" style="Z-INDEX: 101; POSITION: absolute; TOP: 56px; LEFT: 264px" /><input type="submit" name="Button1" value="Button" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="Button1" style="Z-INDEX: 102; POSITION: absolute; TOP: 112px; LEFT: 264px" />&nbsp;
    
         </form>
    	
      </body>
    </HTML>
    
    What can i do?
    What i did wrong?

    Sorry about my english.
    Last edited: Jul 21, 2010
    vitorrubio, Jul 21, 2010
    #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. Libs
    Replies:
    0
    Views:
    1,492
  2. Peter Mount
    Replies:
    4
    Views:
    943
    Peter Mount
    Jan 31, 2006
  3. Replies:
    1
    Views:
    3,776
    bruce barker
    Dec 12, 2008
  4. Bill
    Replies:
    1
    Views:
    1,025
    Brian Cryer
    Jul 15, 2011
  5. Sudip
    Replies:
    0
    Views:
    195
    Sudip
    Jul 1, 2005
Loading...

Share This Page