AZZA-KHAMEES
asked on
Displaying alert message from code-behind in ASP.NET
hi Experts
i am trying to execute an alert from code behind
i used the same example from
Displaying alert message from code-behind in ASP.NET
but istead of a button i want to use the same code from an if statement
but its not working , what i am doing wrong
any advice?
i am trying to execute an alert from code behind
i used the same example from
Displaying alert message from code-behind in ASP.NET
but istead of a button i want to use the same code from an if statement
public void Alert(Page page, string message)
{
string jsString = "alert('" + message + "');";
ScriptManager.RegisterStartupScript(page, page.GetType(),
"MyApplication",
jsString,
true);
}
protected void InsertCar(object sender, GridRecordEventArgs e)
{
---some code----
string variable = hdnfldVariable.Value;
if (variable == null || variable == "")
{
Alert(this.Page, "Hello");
}
else
{
--some DB code--
}
}
but its not working , what i am doing wrong
any advice?
ASKER
thank you for the reply, i tried this code but still i am not getting the alert.
the function is being called but i am not getting the alert
the function is being called but i am not getting the alert
Hi,
did you keep break point and see whether it is calling the function or not?
try that in a sample page.
can you post the full code?
did you keep break point and see whether it is calling the function or not?
try that in a sample page.
can you post the full code?
ASKER
i tried it in sample page and its working
but from my web application its not, note that hdnfldVariable.Value is HiddenField
but from my web application its not, note that hdnfldVariable.Value is HiddenField
Yes, I got that as HiddenField.
Can you add the alert to else condition as well and try, as i had posted previously.
I think something on your page is stopping..!!
Can you add the alert to else condition as well and try, as i had posted previously.
I think something on your page is stopping..!!
ASKER
i added in else condition and still the same, i trace the code using break point and i found that the function is being called but the alert is not showing.
ASKER
i even tried to display a label with error messages from code behind also its not appear
System.Web.UI.WebControls.Label lblError = new System.Web.UI.WebControls.Label();
lblError.Text = "hello";
this.Controls.Add(lblError);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it not working. the page get stuck
i think its something related to the component i am using, [Obout], the aler() is working when i am calling the procedure using asp buttons but from Obout grid insert command its not working.
i think its something related to the component i am using, [Obout], the aler() is working when i am calling the procedure using asp buttons but from Obout grid insert command its not working.
ASKER
also i used
tupScript
MessageBox.Show("Please select the emplyee cprno");
and its working in if condition when i run my application from visual studio but when i publish the application to the localhost server the MessageBox is not working from the server, that why i changed the code to ScriptManager.RegisterStar
try this
Open in new window
Open in new window