Showing posts with label determining. Show all posts
Showing posts with label determining. Show all posts

Monday, March 26, 2012

Determining the source of a partial rendering postback

Is there a way to determine (on the server) what trigger/control/event was the source of the postback? How about something that indicates what update panel(s) will be rendered?

I see that the script manager has an IsInAsyncPostBack property, but I'm curious if there is something more specific.

UpdatePanel.IsInPartialRendering does not seem to work.

You could check the _EventTarget for a hint on what triggered the PostBack.

What would you do differently if you knew what triggered the PostBack?


You could use the ScriptManager.AsyncPostBackSourceElementID to determine the source of the asynchronous postback. In terms of what UpdatePanels will get updated, in server code I don't think there is a summary list that lists them because the Update() method can be called by any code and tracking that is difficult if not impossible(?). However, on the client you can use the pageLoaded or pageLoading events of the PageRequestManager to get information about what panels will be created, updated or deleted.

Determining the result of a RequiredFieldValidator

Hi,

In this scenario have a TabContainer with 8 TabPages.

Each TabPage contains 1 UpdatePanel.

Each UpdatePanel contains 5 RadioButtonLists with corresponding RequiredFieldValidators

On each TabPage there is a series of questions that need to be answered by selecting a option from each of the RadioButtonLists. If the user decides to continue to the next TabPage, he will click on the next TabPage's header. The following happens:

1. The clicked TabPage is displayed.

2. An OnClientActiveTabChange is fired to set off a javascript postback.

3. The RequiredFieldValidators checks if all the RadioButtonList is answered.

If everything is answered, the postback fires, the answers is saved server-side in a database and the user is allowed to continue.

If everything is not answered, the postback is canceled.

This works perfectly. The only flaw here is the fact that the TabContainer displays the next TabPagebefore the RequiredFieldValidators validate the RadioButtonLists. This gives me the problem of even though the user didn't answer all his questions on the previous TabPage, he can now view and answer the questions on the next TabPage. Is there a way I can determine the result of a RequiredFieldValidator on the clientside, so that I can switch the user back to the TabPage which isn't completed yet?

Part of your issue is that Client Script on the Validators do not work inside UpdatePanels (see last bullet point here:http://blogs.visoftinc.com/archive/2007/09/23/asp.net-ajax--updatepanel-not-working--common-problems.aspx) There is a link to UpdatePanel friendly validators on that page as well.

To determine if the validator is valid, check IsValid on the validator client side.

Hope this helps.

-Damien


Seehttp://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx for the way to get your validators to work inside an updatepanel. It is probably not a tab issue at all.


Thanks for the reply.

I have found the selution to my problem. All I had to do was to intercept the onpropertychange event of the RequiredFieldValidator, filter out the irrelevant properties and test if 'isvalid' was true or false. If there are any questions regarding this situation, please don't hesitate to e-mail me.

function SimPostback(sender,args)//Registered on the TabContainer's onclientactivetabchanged event

{

TabContainer = sender;

selectedIndex = (sender.get_activeTabIndex());

if(selectedIndex != LastSelectedTab)

{

document.getElementById('ctl00$cphForm$tcMainTabContainer$ctl00$Button'+(LastSelectedTab)).click();

}

}

function RequiredFieldValidator_CheckValid(RFVObj)//Register on the RequiredFieldvalidator's onpropertychange event

{

var rfv = document.getElementById(RFVObj);

var EventName = event.propertyName;
if(EventName =="isvalid")

{

if(rfv.attributes["isvalid"].value =='false')

{

TabContainer.set_activeTabIndex(LastSelectedTab);

}

}

}