The below picture shows the page developed in C#, This page contains some form elements text box, data table and buttons.
Error Case:
The user goes the another page (mostly time this is a classing list page) and redirect again to this form page. After that, user filling the form again and click any button.
In this scenario, GetStateFromUI trigger multiple times(with old form values and current filled form values therefore API trigger two times )
-> In addition to that, If user send forms one time(everything works), and again a second(current form and old form send to getstatefromui) and again third times multiple api calling(old forms and current form sending to the same getstatefromui method.).
Note: The users authenticate to application and filling form elements,after that click the any buttons. In this case everything works fine. API trigger one times.
I debugged it but I couldn’t catch error case when I try everytime api trigger one times. Everything works fine. Why this error happens? Somehow, users register more than one script and when one is triggered, the others are triggered as well but I can not prove it because I can not catch this error.
I am suspicious, this error’s reason is script registration. but I can not sure. I am thinking changing popup structure with no using script registration.
In Demo.aspx:
// Panel & TextBox & Datatable definitions and then buttons ...
<asp:button id="btn1" runat="server" Text="btn1" OnClick="btn1_Click" />
<asp:button id="btn2" runat="server" Text="btn1" OnClick="btn2_Click" />
<asp:button id="btn3" runat="server" Text="btn1" OnClick="btn3_Click" />
<asp:HiddenField ID="hdnButton1ConfirmCheck" />
<asp:HiddenField ID="hdnButton2ConfirmCheck" />
<asp:HiddenField ID="hdnButton3ConfirmCheck" />
<script type="text/javascript">
...
if(data == 'Button1StartPopup') {
$hdnButton1ConfirmCheck.setValue('Button1Confirm');
__doPostBack('Button1StartPopup', '');
}
if(data == 'Button2StartPopup') {
$hdnButton2ConfirmCheck.setValue('Button2Confirm');
__doPostBack('Button2StartPopup', '');
}
if(data == 'Button3StartPopup') {
$hdnButton3ConfirmCheck.setValue('Button3Confirm');
__doPostBack('Button3StartPopup', '');
}
...
</script>
In Demo.aspx.cs
public override void GetStateFromUI() {
string eventTarget = Request.Form["__EVENTTARGET"];
if(eventTarget == "Button1StartPopup") {
MyButton1Method();
}
if(eventTarget == "Button2StartPopup") {
MyButton2Method();
}
if(eventTarget == "Button3StartPopup") {
MyButton3Method();
}
}
privte void Button1Method(){
if(!string.Equals(hdnButton1ConfirmCheck.Value, "Button1Confirm")) return;
hdnButton1ConfirmCheck.Value = string.Empty;
var request = new DemoRequestForButton1();
var response = DemoServer.demoApi(request);
if(response?.header != null && response?.header.Success) {
ClientScript.RegisterStartupScript(Page.GetType(),"SuccessScript", "alert("Operation
Success");", true);
} else {
ClientScript.RegisterStartupScript(Page.GetType(),"FailedScript", "alert("Operation
Failed");", true);
}
}
private void Button2Method(){
if(!string.Equals(hdnButton2ConfirmCheck.Value, "Button2Confirm")) return;
hdnButton2ConfirmCheck.Value = string.Empty;
var request = new DemoRequestForButton2();
var response = DemoServer.demoApi(request);
if(response?.header != null && response?.header.Success) {
ClientScript.RegisterStartupScript(Page.GetType(),"SuccessScript", "alert("Operation
Success");", true);
} else {
ClientScript.RegisterStartupScript(Page.GetType(),"FailedScript", "alert("Operation
Failed");", true);
}
}
private void Button3Method(){
if(!string.Equals(hdnButton3ConfirmCheck.Value, "Button3Confirm")) return;
hdnButton3ConfirmCheck.Value = string.Empty;
var request = new DemoRequestForButton3();
var response = DemoServer.demoApi(request);
if(response?.header != null && response?.header.Success) {
ClientScript.RegisterStartupScript(Page.GetType(),"SuccessScript", "alert("Operation
Success");", true);
} else {
ClientScript.RegisterStartupScript(Page.GetType(),"FailedScript", "alert("Operation
Failed");", true);
}
}
protected void Btn1_Click(object sender, EventArgs e) {
RegisterScriptForButtons("Is Buttons1 Operation Work Ok", "Button1StartPopup");
}
protected void Btn2_Click(object sender, EventArgs e) {
RegisterScriptForButtons("Is Buttons2 Operation Work Ok", "Button2StartPopup");
}
protected void Btn3_Click(object sender, EventArgs e) {
RegisterScriptForButtons("Is Buttons3 Operation Work Ok", "Button3StartPopup");
}
protected void RegisterScriptForButtons(string popupMessage, string data) {
string script = string.Format("$(document).ready(function(){ -- small confirmation popup code in different framework });", "Operation Result", popupMessage );
ClientScript.RegisterStartupScript(Page.GetType(),"ButtonOperation",script, true);
}