On redux-form, I can propagate a general form error from an async submit handler by throwing a SubmissionError just like described here. However, this doesn't seem to work when my submit handler doesn't return a promise. Is there way to achieve the same error propagating behavior of async submit handler with sync submit handler?
Related
I want to implement a finite state machine (FSM) inside a typical ASP.NET web form. I would like the FSM "engine" to be automatically invoked each time a Page_Load() event happens - which is easy enough - but I also want the engine to receive information about which event caused the Page_Load() to occur. The difficulty is that in an ASP.NET web form, a user-controlled event, such as a button click, can cause the page to reload, but the event handler for the button click itself does not get invoked until after the Page_Load() event fires. As far as I can tell, the Page_Load() handler itself does not contain any information about what user event caused the page to reload. I would prefer not to have to explicitly invoke the FSM engine from within each event-handler method. Is there any way to accomplish this? -- to have Page_Load(), or some other stage in the page life-cycle, "know" what particular user action caused the page to reload?
ASP.NET Web forms will store it in a parameter in the Request object. You can get it like this:
// Find the control name
string nameOfControlWhichCausedPostback = page.Request.Params.Get("__EVENTTARGET");
Then find the control with that name:
if (!String.IsNullOrWhitespace(nameOfControlWhichCausedPostback ))
{
var ctrl = page.FindControl(nameOfControlWhichCausedPostback );
}
I have following code inside a button click handler. Both approaches work fine. The Page_ClientValidate() causes an extra validation check and do processing whereas Page_IsValid makes use of existing property.
QUESTIONS
In case of button click, is it always guaranteed that Page_IsValid would have been calculated by that time? If is not guaranteed, we need to call Page_ClientValidate() explicitly.
What are the events that happen before Page_IsValid is set? For such events we should not rely on Page_IsValid
UPDATE
Is it assured that the button click event handler (in JavaScript) will be called only after the validation part is completed (i.e., after Page_ClientValidate() was invoked as part of validation) ? If this is assured, can I rely on Page_IsValid?
SCRIPT
$('#btnSave').click(function (e) {
//Aproach 1
var isValid = Page_ClientValidate('');
if (isValid)
{
//Do reamining work
}
//Aproach 2
if (Page_IsValid)
{
//Do reamining work
}
});
REFERENCES:
Hide redundant error message in ASP.Net ValidationSummary
Validator causes improper behavior for double click check
Page_ClientValidate is not defined
Page_ClientValidate is validating multiple times.
MSDN - ASP.NET Validation in Depth
In case of button click, Page_ClientValidate() is called when (and only when) the button's CausesValidation is set to true.
Page_ClientValidate() is part of process of doing postback, so it is called within button's click.
I rely on Page_IsValid only in a scope of a function after calling Page_ClientValidate(). Otherwise I always call Page_ClientValidate().
Comment: calling Page_ClientValidate() repeatedly may cause the page to be too obtrusive (multiple alerts etc.). That's why it's good to have a custom validate function that takes care of all validation.
I capture the initializeRequest AJAX event using Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializePostback).
Inside the InitializePostback function, I can successfully get the item that triggered the postback by calling args.get_postBackElement(), but this is not enough info for me, I also need to get the postback argument that was sent with the postback. How can I do this?
OK, I found out what I need to do. Because the postback event argument is allways stored in a hidden tag named "__EVENTARGUMENT", we can simply access that:
var postbackArgument = document.getElementById('__EVENTARGUMENT');
if (postbackArgument) if (postbackArguments.value == 'Objects') {
// Do stuff here
}
I was not sure if this value was set at the time the initializeRequest AJAX event was triggered, but when I tried it worked. Yess!
I know why it's happening and i turned the validation off on the page level, but is there a way to turn it off on the control level?
"Invalid Postback or callback argument . Event validation is enabled
using in configuration or <%# Page EnableEventValidation="true" %>in a
page. For security purposes, this feature verifies that arguments to
Postback or callback events originate from the server control that
originally rendered them. If the data is valid and expected, use the
ClientScriptManager.RegisterForEventValidation method in order to
register the Postback or callback data for validation."
look this post.
Invalid postback or callback argument. Event validation is enabled using '<pages enableEventValidation="true"/>'
in this, i've used Subclass ListBox method. it works...
I have a button that is within an updatepanel control. The button's click event has a function defined for it through JQuery. Once the async postback completes the JQuery event fails to fire when the button is clicked subsequently. What do I need to do to correct this behavior and maintain the JQuery event attachment to the button's click event once it has been refreshed asynchronously?
put your jquery event handler binding inside the following function
function pageLoad(sender,args) {
// binding code here, for example
$('#button').click(function(e) {
// do something when the click event is raised
});
}
pageLoad is executed after every postback, synchronous or asynchronous. pageLoad is a reserved function name in ASP.NET AJAX that is for this purpose. $(document).ready() on the other hand, is executed only once, when the DOM is initially ready/loaded.
See this Overview of ASP.NET AJAX client lifecycle events