mardi 17 février 2015

Attributes.add, ScriptManager.RegisterStartupScript, ScriptManager.RegisterClientScriptBlock not working


I have a button on a webform, inside an update panel that is inside an Ajax Toolkit tabcontainer, that saves data in the textboxes to the database. I have five if statements that validate date ranges on the page and put up an alert if the ranges are invalid using (for example):



If <condition> Then
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "alertMessage", "alert('Actual end date cannot be earlier than Sign date.');", True)
updateFlag = False
End If


This code works fine. A flag is set for updating the data. The problem is if the code falls through the if into the update section: the alert I put there saying "Data saved" doesn't pop up after the updates are done. I've used each of the following:



ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "alertMessage", "alert('Job saved.');", True)
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alertMessage", "alert('Job saved.');", True)
Me.btnSave.Attributes.Add("onclick", "alert('Job saved.');")
ClientScript.RegisterStartupScript() 'don't have the rest of this line


None of them have worked. The data is saved as it should be; it's as if the code jumps over the alert line. I would be very grateful if anyone could help me.


Edit: clarifying that I put Me.btnSave.Attributes.Add("onclick", "alert('Job saved.');") in the Page_Load as well as after the update statements, but that one fires before the data is actually saved, so that error messages are received after the data is "saved". Wrong order, can't use it.





Aucun commentaire:

Enregistrer un commentaire