Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript alert is not working in Update Panel in asp.net

I am working on asp.net web application. I have one UpdatePanel and there is table inside table which has data in some TextBoxes.

I have one save button too inside this UpdatePanel So I want to save this data into Database, when I click Save Button.

This is working fine till now.

But I want to show alert message to User that information saved successfully. I'm using javascript for this purpose, But Javascript is not working. so is this possible to achieve the desired functionality using javascript, if yes then please guide me Or if there is any other alternative method except this please let me know.

Thanks, Vivek

like image 249
vivek jain Avatar asked Nov 18 '13 09:11

vivek jain


2 Answers

If you have update panel use ScriptManager.RegisterClientScriptBlock as below

ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Member Registered Sucessfully');", true)

Remember that you can't use Response.Write during an asynchronous postback.

It would be good if you have posted your code here.

like image 73
Monika Avatar answered Nov 18 '22 19:11

Monika


Try This Line of Code Its Definitely work with Update panel.

var message = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize("Bill No. : " + BillNo + " successfully generated.");
            var script = string.Format("alert({0});window.location ='ChhallanPrint.aspx';", message);
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", script, true);
like image 40
Gautam Kumar Sahu Avatar answered Nov 18 '22 19:11

Gautam Kumar Sahu