lanzar un alert después de que la pagina ha cargado completamente.
Para mostrar un mensaje:
Debemos agregar la librería de jquery, la podemos bajar desde http://jquery.com/.
En la pagina aspx:
Agregar la referencia a la libreria:
<script type="text/javascript" src="../../Scripts/jquery-1.7.2.js"></script>
En el Code Behind:
Dentro del método Page_Load agregamos esta linea para mostrar en el alert el valor de la variable auxMsg.
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Mensaje_" + DateTime.Now.ToString(), "$(document).ready(function () {alert('Han ocurrido los siguientes errores: " + auxMsg + "')});", true);
Créditos:
En esta pagina hay un ejemplo de llamada al método document.ready()
http://www.learningjquery.com/2006/09/introducing-document-ready
Mostrando entradas con la etiqueta alert. Mostrar todas las entradas
Mostrando entradas con la etiqueta alert. Mostrar todas las entradas
lunes, 7 de mayo de 2012
lunes, 11 de abril de 2011
Error alert al intentar mostrar exception.
Las soluciones al error son las siguientes:
//if you have AJAX support (even if you aren't using it), use this:
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);
//if you're using asp.net 2.0 and have no access to MS AJAX, use this: ClientScript.RegisterClientScriptBlock(typeof(Page), "uniqueOtherKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);
A mi me funcionó la primera, como ven la solución es el Replace.
//if you have AJAX support (even if you aren't using it), use this:
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);
//if you're using asp.net 2.0 and have no access to MS AJAX, use this: ClientScript.RegisterClientScriptBlock(typeof(Page), "uniqueOtherKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);
Lo vi en:
http://forums.asp.net/t/1292611.aspx
A mi me funcionó la primera, como ven la solución es el Replace.
Replace("'", "")
Ahora he hecho una solucion mas sofisticada o menos fea, creo una clase en
la capa de negocio asi:
namespace Proyecto.Business.Util { public static class Conversion {
public static string QuitaCaracterRaro(string str) { string[] arregloCaracteresRaros = { "'", "\n", "\t", "\r" }; foreach (string element in arregloCaracteresRaros) { str = str.Replace(element, ""); } return str; }
} }
y la utilizo del siguiente modo:
ScriptManager.RegisterStartupScript(this.Page, GetType(), "Aviso" + DateTime.Now,
"alert('Houston, tenemos problemas. Detalle = " + Conversion.QuitaCaracterRaro(ex.Message)
+ "');", true);
Suscribirse a:
Entradas (Atom)