Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Validator not working when inside UpdatePanel (http://www.velocityreviews.com/forums/t781126-validator-not-working-when-inside-updatepanel.html)

Nathan Sokalski 12-04-2009 07:41 PM

Validator not working when inside UpdatePanel
 
I have a new validator (inherits from BaseValidator), but it does not always
work when it is inside an UpdatePanel. When I use it inside an update panel,
it works fine until I do the first successful submit. After the first
successful submit, the validator basically acts as if it is no longer there.
Why could this be happening? Any help would be appreciated. Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/



Gregory A. Beamer 12-04-2009 08:04 PM

Re: Validator not working when inside UpdatePanel
 
"Nathan Sokalski" <njsokalski@hotmail.com> wrote in
news:#b4FBnRdKHA.2596@TK2MSFTNGP04.phx.gbl:

> I have a new validator (inherits from BaseValidator), but it does not
> always work when it is inside an UpdatePanel. When I use it inside an
> update panel, it works fine until I do the first successful submit.
> After the first successful submit, the validator basically acts as if
> it is no longer there. Why could this be happening? Any help would be
> appreciated. Thanks.


Having not tried this, my assumption would be that the intiial state is
changed once the submit is done. This means you need a bit of JavaScript
to re-activate it.

To confirm this, I would consider using Firefox with Firebug, or
similar, to debug the AJAX.

For IE, you can use Fiddler, but it takes a bit more work as it is an
"external" tool.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************

Nathan Sokalski 12-05-2009 02:51 AM

Re: Validator not working when inside UpdatePanel
 
I have never used Firebug or Fiddler before, although I have heard of and
seen them so I don't expect to have any problem using them. However, because
my situation does not involve recieving an error, and I do not know exactly
what is getting changed when I submit, I really don't have any idea where to
start as far as what to look for. Can you help me get started? Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

"Gregory A. Beamer" <NoSpamMgbworld@comcast.netNoSpamM> wrote in message
news:Xns9CD78EDF2AAF3gbworld@207.46.248.16...
> "Nathan Sokalski" <njsokalski@hotmail.com> wrote in
> news:#b4FBnRdKHA.2596@TK2MSFTNGP04.phx.gbl:
>
>> I have a new validator (inherits from BaseValidator), but it does not
>> always work when it is inside an UpdatePanel. When I use it inside an
>> update panel, it works fine until I do the first successful submit.
>> After the first successful submit, the validator basically acts as if
>> it is no longer there. Why could this be happening? Any help would be
>> appreciated. Thanks.

>
> Having not tried this, my assumption would be that the intiial state is
> changed once the submit is done. This means you need a bit of JavaScript
> to re-activate it.
>
> To confirm this, I would consider using Firefox with Firebug, or
> similar, to debug the AJAX.
>
> For IE, you can use Fiddler, but it takes a bit more work as it is an
> "external" tool.
>
> Peace and Grace,
>
> --
> Gregory A. Beamer (MVP)
>
> Twitter: @gbworld
> Blog: http://gregorybeamer.spaces.live.com
>
> *******************************************
> | Think outside the box! |
> *******************************************




bruce barker 12-05-2009 03:36 AM

Re: Validator not working when inside UpdatePanel
 
if your validator is in an update panel, then you have to code it
correctly. your validator is rendered as a span, and will be replaced
along with any other dom objects in the panel(s). this means you need to
rerun init code. if it registers any client script, it must use
ScriptManager to doit. if it references any $gets(), they must be redone.

-- bruce (sqlwork.com)




Nathan Sokalski wrote:
> I have a new validator (inherits from BaseValidator), but it does not always
> work when it is inside an UpdatePanel. When I use it inside an update panel,
> it works fine until I do the first successful submit. After the first
> successful submit, the validator basically acts as if it is no longer there.
> Why could this be happening? Any help would be appreciated. Thanks.


Nathan Sokalski 12-05-2009 05:48 AM

Re: Validator not working when inside UpdatePanel
 
OK, I think that I have confirmed that is my problem. The init script that I
need to rerun is a script generated by ASP.NET to set the attributes I add
when overriding the AddAttributesToRender method inherited from
BaseValidator. This script looks something like the following:

var ctl00_cphExampleContent_ctl00 = document.all ?
document.all["ctl00_cphExampleContent_ctl00"] :
document.getElementById("ctl00_cphExampleContent_c tl00");
ctl00_cphExampleContent_ctl00.controltovalidate =
"ctl00_cphExampleContent_txtMinimum";
ctl00_cphExampleContent_ctl00.errormessage = "You must enter at least 5
characters.";
ctl00_cphExampleContent_ctl00.display = "Dynamic";
ctl00_cphExampleContent_ctl00.validationGroup = "minimum";

The script is obviously very simple, but because it is automatically
generated, how can I rerun it? Also, because this is a validator that I am
creating to be shared between multiple applications and users, I do not
actually know whether it will be inside an UpdatePanel or not, so I either
need to detect that as a condition in the validator or have code that works
in either scenario. Any ideas? Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

"bruce barker" <nospam@nospam.com> wrote in message
news:uAqGywVdKHA.5156@TK2MSFTNGP04.phx.gbl...
> if your validator is in an update panel, then you have to code it
> correctly. your validator is rendered as a span, and will be replaced
> along with any other dom objects in the panel(s). this means you need to
> rerun init code. if it registers any client script, it must use
> ScriptManager to doit. if it references any $gets(), they must be redone.
>
> -- bruce (sqlwork.com)
>
>
>
>
> Nathan Sokalski wrote:
>> I have a new validator (inherits from BaseValidator), but it does not
>> always work when it is inside an UpdatePanel. When I use it inside an
>> update panel, it works fine until I do the first successful submit. After
>> the first successful submit, the validator basically acts as if it is no
>> longer there. Why could this be happening? Any help would be appreciated.
>> Thanks.




bruce barker 12-05-2009 07:08 PM

Re: Validator not working when inside UpdatePanel
 
inline script (writer.write) will not work because when the client
script in update panel sets the innerHTML, any script in the html is
ignored by the browser.

use ScriptManager.RegisterStartupScript to render the script. or as it
looks like you are only setting properties, use
ScriptManager.RegisterExpandoAttribute.

to work with update panels you must use ScriptManager, not the old
ClientScript.

-- bruce (sqlwork.com)


Nathan Sokalski wrote:
> OK, I think that I have confirmed that is my problem. The init script that I
> need to rerun is a script generated by ASP.NET to set the attributes I add
> when overriding the AddAttributesToRender method inherited from
> BaseValidator. This script looks something like the following:
>
> var ctl00_cphExampleContent_ctl00 = document.all ?
> document.all["ctl00_cphExampleContent_ctl00"] :
> document.getElementById("ctl00_cphExampleContent_c tl00");
> ctl00_cphExampleContent_ctl00.controltovalidate =
> "ctl00_cphExampleContent_txtMinimum";
> ctl00_cphExampleContent_ctl00.errormessage = "You must enter at least 5
> characters.";
> ctl00_cphExampleContent_ctl00.display = "Dynamic";
> ctl00_cphExampleContent_ctl00.validationGroup = "minimum";
>
> The script is obviously very simple, but because it is automatically
> generated, how can I rerun it? Also, because this is a validator that I am
> creating to be shared between multiple applications and users, I do not
> actually know whether it will be inside an UpdatePanel or not, so I either
> need to detect that as a condition in the validator or have code that works
> in either scenario. Any ideas? Thanks.


Nathan Sokalski 12-06-2009 09:29 PM

Re: Validator not working when inside UpdatePanel
 
I'm sorry, I think I gave incorrect information in my original post. The
script does not set the attributes set in AddAttributesToRender, it sets
several expando attributes used by validators (which, as you could probably
see, in this case included controltovalidate, errormessage, display, and
validationGroup). But I think you misunderstood what I meant when I said the
script is generated by ASP.NET. I am not using ScriptManager OR ClientScript
directly; the script I showed you is added by the BaseValidator class in
code that I do not see (or at least I don't know where it is), I believe
that it is a script that is created regardless of what I do. Because I am
not the one who writes the code that adds this script, where can I go to fix
my problem (or is there a function and/or property that returns the script
that gets generated so that I can rerun the script at the appropriate
time?)? Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

"bruce barker" <nospam@nospam.com> wrote in message
news:%23i81N5ddKHA.2460@TK2MSFTNGP04.phx.gbl...
> inline script (writer.write) will not work because when the client script
> in update panel sets the innerHTML, any script in the html is ignored by
> the browser.
>
> use ScriptManager.RegisterStartupScript to render the script. or as it
> looks like you are only setting properties, use
> ScriptManager.RegisterExpandoAttribute.
>
> to work with update panels you must use ScriptManager, not the old
> ClientScript.
>
> -- bruce (sqlwork.com)
>
>
> Nathan Sokalski wrote:
>> OK, I think that I have confirmed that is my problem. The init script
>> that I need to rerun is a script generated by ASP.NET to set the
>> attributes I add when overriding the AddAttributesToRender method
>> inherited from BaseValidator. This script looks something like the
>> following:
>>
>> var ctl00_cphExampleContent_ctl00 = document.all ?
>> document.all["ctl00_cphExampleContent_ctl00"] :
>> document.getElementById("ctl00_cphExampleContent_c tl00");
>> ctl00_cphExampleContent_ctl00.controltovalidate =
>> "ctl00_cphExampleContent_txtMinimum";
>> ctl00_cphExampleContent_ctl00.errormessage = "You must enter at least 5
>> characters.";
>> ctl00_cphExampleContent_ctl00.display = "Dynamic";
>> ctl00_cphExampleContent_ctl00.validationGroup = "minimum";
>>
>> The script is obviously very simple, but because it is automatically
>> generated, how can I rerun it? Also, because this is a validator that I
>> am creating to be shared between multiple applications and users, I do
>> not actually know whether it will be inside an UpdatePanel or not, so I
>> either need to detect that as a condition in the validator or have code
>> that works in either scenario. Any ideas? Thanks.




bruce barker 12-07-2009 12:06 AM

Re: Validator not working when inside UpdatePanel
 
the .net validators with 3.5 (webextensions.dll) were rewritten to use
ScriptManger. I don't know where your validator is from, but you need an
update panel aware one.

-- bruce (sqlwork.com)

Nathan Sokalski wrote:
> I'm sorry, I think I gave incorrect information in my original post. The
> script does not set the attributes set in AddAttributesToRender, it sets
> several expando attributes used by validators (which, as you could probably
> see, in this case included controltovalidate, errormessage, display, and
> validationGroup). But I think you misunderstood what I meant when I said the
> script is generated by ASP.NET. I am not using ScriptManager OR ClientScript
> directly; the script I showed you is added by the BaseValidator class in
> code that I do not see (or at least I don't know where it is), I believe
> that it is a script that is created regardless of what I do. Because I am
> not the one who writes the code that adds this script, where can I go to fix
> my problem (or is there a function and/or property that returns the script
> that gets generated so that I can rerun the script at the appropriate
> time?)? Thanks.


Nathan Sokalski 12-07-2009 01:11 AM

Re: Validator not working when inside UpdatePanel
 
I am using Visual Studio 2008 and ASP.NET 3.5, and my validator is one that
I wrote which inherits from BaseValidator (the validator was written using
Visual Studio 2008 and ASP.NET 3.5 as well). Any more suggestions or ideas?
Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

"bruce barker" <nospam@nospam.com> wrote in message
news:ed4AqEtdKHA.4112@TK2MSFTNGP06.phx.gbl...
> the .net validators with 3.5 (webextensions.dll) were rewritten to use
> ScriptManger. I don't know where your validator is from, but you need an
> update panel aware one.
>
> -- bruce (sqlwork.com)
>
> Nathan Sokalski wrote:
>> I'm sorry, I think I gave incorrect information in my original post. The
>> script does not set the attributes set in AddAttributesToRender, it sets
>> several expando attributes used by validators (which, as you could
>> probably see, in this case included controltovalidate, errormessage,
>> display, and validationGroup). But I think you misunderstood what I meant
>> when I said the script is generated by ASP.NET. I am not using
>> ScriptManager OR ClientScript directly; the script I showed you is added
>> by the BaseValidator class in code that I do not see (or at least I don't
>> know where it is), I believe that it is a script that is created
>> regardless of what I do. Because I am not the one who writes the code
>> that adds this script, where can I go to fix my problem (or is there a
>> function and/or property that returns the script that gets generated so
>> that I can rerun the script at the appropriate time?)? Thanks.




Gregory A. Beamer 12-07-2009 05:32 PM

Re: Validator not working when inside UpdatePanel
 
"Nathan Sokalski" <njsokalski@hotmail.com> wrote in
news:unHDfXVdKHA.1648@TK2MSFTNGP05.phx.gbl:

> I have never used Firebug or Fiddler before, although I have heard of
> and seen them so I don't expect to have any problem using them.
> However, because my situation does not involve recieving an error, and
> I do not know exactly what is getting changed when I submit, I really
> don't have any idea where to start as far as what to look for. Can you
> help me get started? Thanks.


Video or text?

There are quite a few links that talk about debugging AJAX on this
Google search:
http://snurl.com/tlfyg

The top link is a You Tube video that shows how to do it.

The search (above) is where I would start. if that yields nothing, then
we can look at other options.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************


All times are GMT. The time now is 04:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.