I am saving a form in ASP.Net and C#. Every thing works fine except the message after save is not displayed. It is getting lost somewhere in between i am not able to figure why?
protected void btnSave_Click(object sender, EventArgs e)
{
int fisherId;
try
{
if (ValidateControls())
{
_traceLog.AppendLine("Fisheries Registration Form saving : btnSave_Click() ");
FillDemographicsObjects();
if(_manager.CreateFisherDemographics(_demographics, _address, "Test User",out fisherId))
{
/*ShowMessage(IntertribalFishriesResource.msgSaveSuccess);*/
if (_shared.SendMailToFisher(fisherId))
{
_traceLog.AppendLine("Fisheries Registration Form ending : btnSave_Click() ");
Response.Redirect("~/Fisher/FisherRegistration.aspx?Id=" + fisherId, false);
}
}
}
}
catch (Exception ex)
{
_userException.CreateExceptionLog(ex);
}
finally
{
_userException.CreateTraceLog(_traceLog.ToString());
}
}
Message displayed in greyed text is not executed. ShowMessage is given below:
protected bool ShowMessage(string message)
{
if (message.Length > 0)
{
hidErrMsg.Value = message;
ScriptManager.RegisterStartupScript(upFisherRegistration, this.GetType(), "myScript", "ShowMessage();",true);
return false;
}
return true;
}
What I want to achieve is that , after successful save operation , i want to display message and redirect the page. Thats all.
HI,
when you add RegsiterStartupScript this will be executed for current Request session and it will be written to response, if you redirect after it than your message wont be shown because script doesn’t exists in response.
What you need to do is add another parameter in redirect url like &showSaveMessage=true
and on redirected page check if showSavemessage is true add Register startup script method.
I hope this helps