Showing posts with label validation. Show all posts
Showing posts with label validation. Show all posts

Monday, March 26, 2012

Asp.Net Ajax and Validation

Hello,

I'm still fairly new to ASP.Net, so I hope someone can point me in the right direction. I created a test project to examine the use of the ASP.Net AJAX components. I created a simple page with the following structure

Page

- Label: Shows current date/time
- Button: Has a click event with no code, just to trigger the time change

- Update Panel 1
- ListBox
- 2 buttons: code to move items in listbox up and down

- Update Panel 2
- TextBox
- Button: has a click even with no code to trigger update panel
- Asp Required Field Validator: for the TextBox
- ValidatorCalloutExtender: for the required field validator

So, here's my question. The way I understood it, by putting the items in an update panel, events triggered in that panel only updates the panel. So, for example, by pushing one of the buttons in UpdatePanel1, I wouldn't trigger the label on the main page to show the updated time. That part seems to work ok. However, when I added the validation items into the 2nd update panel, no matter what I do, the validation fires if the field is blank. Is that simply a function of validation, or is there something I need to add somewhere that would force UpdatePanel2 to fire on its own? Thanks.

Try making your UpdatePanel conditional:

<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional">


Actually, did some more research and found that there's apparently a bug with validation and AJAX UpdatePanel. See here for the fix:

http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx

It also helped me to use the ValidateGroup property on the button and the RequiredFieldValidator

Saturday, March 24, 2012

Asp.net Ajax - Validation Controls

Hi, i created a ajax modal popup with some text controls and validation controls on it programmatically and attached this to be shown on click event of hyperlink. The modaI popup is working. I enable client validation on validation controls. When i submit the modal popup, validation is taking place on the client side, but the modal popup is closing instead of displaying the validation messages. Any help is appreciated.

Regards

Subba

Not sure which Validation controls you're using but you may want to check out the validator controls that are part of the System.Web.UI.Compatibility namespace (separate assembly that you need to download).

We were having a problem when using the default validation controls on an Ajax page, that despite the validation failing on the client side the page still went back to the server. We had to change the validators...check out the two links below.

http://weblogs.asp.net/scottgu/archive/2007/01/25/links-to-asp-net-ajax-1-0-resources-and-answers-to-some-common-questions.aspx

http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx

Regards,

Tim


Tim, I installed the hot fix 'KB934839' and i donno whether this hot fix solved the validation control - ajax issue or not. By the way, i'm using validation summary and required field validator on my modal popup.


Sorry.. wrong post for your reply... I installed the hot fixhttp://support.microsoft.com/?kbid=933383. Let me give a try for your solution. Thanks.


Tim, i did go throughhttp://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx and referenced validators.dll, modified web.config. but no luck.. stil the modal popup is not shown with the requried field validators error message. i need to click on the hyperlink to show the modal popup again with those validation messages..


Hi,

That's because the close function is implemented with javascript, and the failure of validators won't prevent it from happenning.

You may try this:

1. Don't specify a button as the OK button for the ModalPopup

2. Add a click event for that button to close the popup

function closePopup()
{
var result =ValidatorOnSubmit();
if (result == true) // only close it when validation successes
{
var modalPopup = $find('ModalPopupExtender1');
modalPopup.hide();
}
}

Hope this helps.


Raymond, modalPopup is null in the page script and is erroring out..


The sample code I provided is used to express the idea of how to implement it. It may not work directly.

You may need to modify it accordingly.

asp.net 2.0: is there any where where we can check ajax version

Hi,

Sometimes I run into problems in the server that I don t run in my developement machine, especially regardingAjax,validation,Ajax control toolkitlikeValidatorCalloutExtender...etc

Are you aware if there re different versions of Ajax or any thing else that might be causing these little weird behaviours on the production machine different from our dev machines?

If so how can we check the Ajax or customValidators version?

I m just making a hypothesis, let me know pls if any other possibility?

Thank thee

You can check the version of the currently installed Ajax Control Toolkit.dll by going to C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\AJAX Control Toolkit\Binaries and setting the view to Tiles or just hovering your mouse over the AjaxControlToolkit.dll. The latest version is currently 1.0.10920.0.

You can also check the versions of the AJAX individual controls by right-clicking in the Toolbox and selecting Choose Items then under the tab .NET Framework Components you can scroll through and check the versions of all the AJAX Controls by clicking on them.


hello.

another option is to look at the web.config file and see the info that is shown on the <assemblies> element...


I can t check that, because all those files are copied from my development machine to the server anyway, so obviously the web.config file is the same and gonna say the same version. There must be something outside the web site solution that interfers.

I can't check toolbox in the server since there is no visual studio there. On my dev machine , the ajaxcontrolToolkit controls version is: 1.0.10618.0

One more thing, when I remove the UpdatePanel from my page, every thing works well.

Thanks for tryimg to help me.


Is the ajaxcontroltoolkit.dll version on the server the same as the one on your dev box? Also if you haven't already, take a look at the following link and more specifically the section "Controls that Are Not Compatible with UpdatePanel Controls". I'm not sure if this will help, but if nothing else you'll be better informed.Smile

http://www.asp.net/ajax/documentation/live/overview/UpdatePanelOverview.aspx


hello.

tutus:

I can t check that, because all those files are copied from my development machine to the server anyway, so obviously the web.config file is the same and gonna say the same version. There must be something outside the web site solution that interfers.

well, then use reflector to load the dlls and check the versions of the assemblis you want

btw, if you're building a 2.0 web site, you'll need to download the compat validators since the ones that come with asp.net 2.0 don't work with the updatepanel.

Wednesday, March 21, 2012

ASP .NET Ajax Validation - MaskedEdit

Hello,

I am using the MaskedEditExtender and the MaskedEditValidator, found good very, however in mine in case that, am needing to make with that it does not use no type of culture in the hour to edit, that is, at the moment where clico inside of the box of text and it appears R$ __.___,__ But, I want that he appears only __.___,__ (Without cultureName="Pt-Br")

Att,

Eduardo Bellinat.

I obtained to make to function, I leave below the explanation:


Not toappear the R$ (cultureName of Brazil) or $ (Culture of the USA), it isnecessary to setar the property MaskType= " None ", of this form willgo, at the moment where to clicar in the box of text, only __. ___.___, __

[]'s,


Eduardo Bellinat.