Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation plugin is not working in update panel

Tags:

jquery

asp.net

I have an update panel and inside the panel text boxes and buttons are available. Now I am using the jQuery Validation plugin, but the validation plugin is not working when it is used in the update panel.

For example:

function GetAddressTargetList() {
    var objArray = new Array();
    var objAddressElement = new Object();

    objAddressElement = new Object();
    objAddressElement.Id = "ddlAccType"; 
    objAddressElement.Rules = "required";
    objAddressElement.TargetControlType = "select";
    objArray[objArray.length] = objAddressElement;
    objAddressElement = new Object();
}

and in the page level (.aspx)

$(document).ready(function () {
    GetAddressTargetList();
});

function pageLoad(sender, args) {
    // To load the tooltip in update panel
    if (args.get_isPartialLoad()) {
        GetAddressTargetList();
    }
}

How can I get the validation when I am using the update panel working?

like image 934
Vara Prasad.M Avatar asked Oct 06 '22 14:10

Vara Prasad.M


2 Answers

I think that you have forget to initilize the pageLoad

Add this on your code:

$(document).ready(function () {
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoaded);
});

function PageLoaded(sender, args) {
    GetAddressTargetList();
}

reference: http://msdn.microsoft.com/en-us/library/bb397523(VS.100).aspx

Update

I have update the pageLoad to PageLoaded, to avoid conflict after the comment of the rs. In my opinion the UpdatePanel have a custom way to handle the events and what we try here is to trigger the event on javascript after the UpdatePanel Updates the content.

like image 91
Aristos Avatar answered Oct 10 '22 02:10

Aristos


Try this instead of document.ready, ajax pageLoad is called after every partial postbacks

function pageLoad() { 
    GetAddressTargetList();
  } 
like image 39
rs. Avatar answered Oct 10 '22 02:10

rs.