Hi,
I have to show a message-box when the data gets stored.
I have used this code...
It worked fine when i tested it with demo website...But when i applied it in my web-application, it showed me no error but also the message-box didn't popup.
protected void btnok_Click(object sender, EventArgs e)
{
try
{
string _status = "Pending";
bool _result = _objVreg.insertdata(_strTablename, txtname.Text.ToString(), txtmobileno.Text.ToString(), txtcompany.Text.ToString(), txtpurpose.Text.ToString(), ddlbranch.SelectedValue.ToString(), ddldepartment.SelectedValue.ToString(), ddlcontacperson.SelectedValue.ToString(), txtcity.Text.ToString(), System.DateTime.Now, "", "", _status, txtluggage.Text.Trim());
if (_result == true)
{
Alert.Show("Record Added Successfully");
}
else
{
lblMsg.Text = "Record Not Added, Please Try Again";
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
I have added a class named "Alert.cs" which shows any popup passed as string.
The class is
public static class Alert
{
public static void Show(string message)
{
string cleanMessage = message.Replace("'", "\\'");
string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
}
}
}
Please guide me...
UPDATE:
OP resolved it by himself and posted it as one of the answer.