Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to display alert message based on the events executed in code behind of aspx page i.e. aspx.cs

Is there a way to do it?
Posted

yeah you can,,

either bind the event of javascript to the button or use the code directly in your code behind page
for example:
on button's click event write:

string jscript = "<script>alert('YOUR BUTTON HAS BEEN CLICKED')</script>";
            System.Type t = this.GetType();
            ClientScript.RegisterStartupScript(t, "k", jscript);
 
Share this answer
 
Hi,

try like this,
C#
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Notify", "alert('Notification : Your Message.');", true);
 
Share this answer
 
Using:
MSDN: RegisterClientScriptBlock Method[^] OR
MSDN: RegisterStartupScript Method[^]

Using them, you can inject the scripts into a page from server side and based on certain condition (and specific to page.)
For samples on how to use it: How to Use RegisterClientScriptBlock & RegisterStartupScript[^]
Inject javascript from server - Sample[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900