ASP.NET - show alert - Asked By Jahir on 28-Jan-12 02:03 AM

how to display show alert message in ASP.net tel me Simple codings
Suchit shah replied to Jahir on 28-Jan-12 02:13 AM

Step-1 Create below function in your page

protected void jsCall(string alert)
 
{
 
string script = @"alert('" + alert + "');";
 
ScriptManager.RegisterStartupScript(this, this.GetType(), "jsCall", script, true);
}


Step-2 After creating this function when every you required to display the message just do it like below on page.

  jscall("Recrod saved");
Venkat K replied to Jahir on 28-Jan-12 02:17 AM
The best thing you can do is something like below, it will run the script when you click on the button, you can also change the event to page load event if you want to show alert message in page load:
private void Button1_Click(object sender, System.EventArgs e)
{
string javaScript =
"<script language=JavaScript>\n" +
"alert('Button1_Click client-side');\n" +
"</script>";

RegisterStartupScript("Button1_ClickScript", javaScript);
}



Thanks
Chintan Vaghela replied to Jahir on 28-Jan-12 02:34 AM

Hello,

string strJavaScript = "<script language = javascript type=text/Javascript> alert('ID is not Configured.')</script>";

            this.Page.RegisterClientScriptBlock("Key4", strJavaScript);

Hope this is helpful !

Thanks

 

 

 

 

 

Jahir replied to Chintan Vaghela on 28-Jan-12 02:53 AM
ur coding very nice thank u. but its shows message from webpage in message box header but i want to display there my text what i want to change there in codings ?
Chintan Vaghela replied to Jahir on 28-Jan-12 03:15 AM

Hello,

string strimsg = "Set Alert Message";// Set Your OWN message here

            string strJavaScript = "<script language = javascript type=text/Javascript> alert('" + strimsg + "')</script>";

            this.Page.RegisterClientScriptBlock("Key4", strJavaScript);

Hope this is helpful !

Thanks

 

 

 

 

 

kalpana aparnathi replied to Jahir on 28-Jan-12 05:28 AM

hi,

Here simple way for show alert :

JavaScript is JavaScript - all these frameworks do is offer you different ways of putting the alert('message'); on the page.  You can either write an alert straight to your page


<script type="text/JavaScript">
alert('hello world');

</script>


You can use the ASP.NET codebehind to write it to the page

ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);


You can also response.write it to the page , you can also write the javascript to a literal on the page.
dipa ahuja replied to Jahir on 28-Jan-12 06:11 AM

Using JavaScript simple alert box :

Page.RegisterClientScriptBlock("""<script>alert('Book Added');</script>");

Response.Write("<script>alert('Book Added')</script>");

Or you can display your own window by

using the modalpopupExtender:

CSS Effect

----------

<style type="text/css">

  .modalBackground

  {

  background-color#CCCCFF;

  filteralpha(opacity=40);

  opacity0.5;

  }

  .ModalWindow

  {

  bordersolid1px#c0c0c0;

  background-color#99ccff;

  padding0px10px10px10px;

  positionabsolute;

  top-1000px;

  }

</style>

ModapPopUp Code

------------------------

<cc1:ModalPopupExtender TargetControlID="Button2" BackgroundCssClass="modalBackground"

CancelControlID="btnMsg" PopupControlID="Panel1" PopupDragHandleControlID="btnMsg"

ID="ModalPopupExtender2" runat="server">

</cc1:ModalPopupExtender>

<asp:Panel ID="Panel1" runat="server" CssClass="ModalWindow">

<%--Button popup--%>

<center>

<table runat="server">

<tr>

  <td bgcolor="#cccccc" style="border: 1px; border-color: Black;" height="20px" align="left"

  valign="top">

  <div style="border-bottom-width: 1px; border: 1px solid">

  Deletion</div>

  </td>

</tr>

<tr>

  <td align="center" bgcolor="#99ccff">

  <br />

  The Record has been deleted!

  </td>

</tr>

</table>

<asp:Button ID="btnMsg" runat="server" Text="OK" /><br />

</center>

</asp:Panel>

<asp:Button ID="Button2" runat="server" Text="OK" /><br />



Riley K replied to Jahir on 28-Jan-12 09:48 AM


In simple way you can use JavaScript Alert box,

you can call this from codebehind

Response.Write("<script>alert('Hello');</script>");

Regards