2012-08-04 31 views
18

Tengo un javascript de código subyacente. es mostrar un cuadro de diálogo de JavaScript. Sin embargoEl nombre 'ClientScript' no existe en el contexto actual

, se muestran a mantener este error

The name 'ClientScript' does not exist in the current context 

Este código se coloca dentro masterpage. También había usar exactamente el mismo código en el otro archivo aspx, y salir bien, aparte de esto ..

aquí está mi código:

protected void Button2_Click(object sender, EventArgs e) 
    { 
     string message = "Order Placed Successfully."; 
     System.Text.StringBuilder sb = new System.Text.StringBuilder(); 
     sb.Append("<script type = 'text/javascript'>"); 
     sb.Append("window.onload=function(){"); 
     sb.Append("alert('"); 
     sb.Append(message); 
     sb.Append("')};"); 
     sb.Append("</script>"); 
     ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString()); string script = "alert('abc');"; 

    } 

Respuesta

46

:

Page.ClientScript 

lugar para ver si se hace una diferencia.

3

En la página maestra tratar ScriptManager.RegisterStartupScript() lugar. Cuidado, la firma difiere ligeramente de Page.ClientScript.RegisterClientScriptBlock().

8

Para el archivo cs, la muestra es;

ClientScript.RegisterClientScriptBlock(this.GetType(), "{some text for type}", "alert('{Text come to here}'); ", true); 

para masterpage cs el ejemplo es;

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "{some text for type}", "alert('{Text come to here}'); ", true); 
+0

Tnaks denize para la explicación detallada – BNN

+0

Page.ClientScript funciona en MasterPage. Gracias hombre. –

Cuestiones relacionadas