Response.Write("alert('hi')");显示在页面上

Response.Write("<script   language=javascript>alert('d');</script>");
是弹出提示框,而且必须是在.cs页面,

在html页面中的
<script runat="server">
Response.Write("<script   language=javascript>alert('d');</script>");
</script>
报错:Newline in constant

在html页面中
即便是后台有cs文件也不会触发Page_Load事件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="temp.aspx.cs" Inherits="temp" %>

<script runat="server">
void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
 {

..........................
}
</script>

如果把上述方法放进后台cs文件
page_load()
{
}
void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
 {

..........................
}
page_load是空的,所以页面就呈现出来的是空的。



可以在Page_Load事件里面写:
this.CustomersGridView.DataSource = this.CustomersSqlDataSource;
this.CustomersGridView.DataBind();

这样Page_Load 时就有内容了。
aspx页面:
Response.Write("alert('hi')");显示在页面上<%@ Page Language="C#" AutoEventWireup="true" CodeFile="temp.aspx.cs" Inherits="temp" %>
Response.Write("alert('hi')");显示在页面上
Response.Write("alert('hi')");显示在页面上
<html xmlns="http://www.w3.org/1999/xhtml">
Response.Write("alert('hi')");显示在页面上
<head>
Response.Write("alert('hi')");显示在页面上
<title>GridView</title>
Response.Write("alert('hi')");显示在页面上
</head>
Response.Write("alert('hi')");显示在页面上 
<body>
Response.Write("alert('hi')");显示在页面上    
<form id="Form1" runat="server">
Response.Write("alert('hi')");显示在页面上      
<h3>ButtonField Example</h3>      
Response.Write("alert('hi')");显示在页面上      
<asp:label id="Message"
Response.Write("alert('hi')");显示在页面上        forecolor
="Red"
Response.Write("alert('hi')");显示在页面上        runat
="server"/>                    
Response.Write("alert('hi')");显示在页面上      
<!-- Populate the Columns collection declaratively. -->
Response.Write("alert('hi')");显示在页面上      
<asp:GridView id="CustomersGridView" 
Response.Write("alert('hi')");显示在页面上         AutoGenerateColumns
="false"
Response.Write("alert('hi')");显示在页面上          OnRowCommand
="CustomersGridView_RowCommand"
Response.Write("alert('hi')");显示在页面上         runat
="server">                
Response.Write("alert('hi')");显示在页面上         
<Columns>                               
Response.Write("alert('hi')");显示在页面上          
<asp:ButtonField  ButtonType="Button" 
Response.Write("alert('hi')");显示在页面上            CommandName
="Select" HeaderText="Select Customer" 
Response.Write("alert('hi')");显示在页面上             Text
="Select"/>             
Response.Write("alert('hi')");显示在页面上          
<asp:BoundField  DataField="CompanyName" 
Response.Write("alert('hi')");显示在页面上            HeaderText
="Company Name"/>
Response.Write("alert('hi')");显示在页面上          
<asp:BoundField DataField="ContactName" 
Response.Write("alert('hi')");显示在页面上            HeaderText
="Contact Name"/>                
Response.Write("alert('hi')");显示在页面上         
</Columns>               
Response.Write("alert('hi')");显示在页面上      
</asp:GridView>
Response.Write("alert('hi')");显示在页面上                  
Response.Write("alert('hi')");显示在页面上      
Response.Write("alert('hi')");显示在页面上        
<asp:sqldatasource 
Response.Write("alert('hi')");显示在页面上        id
="CustomersSqlDataSource" 
Response.Write("alert('hi')");显示在页面上        selectcommand
="SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle] FROM [Customers]"
Response.Write("alert('hi')");显示在页面上        connectionstring
="<%$ ConnectionStrings:NorthwindConnectionString %>"
Response.Write("alert('hi')");显示在页面上        runat
="server">
Response.Write("alert('hi')");显示在页面上        
</asp:sqldatasource>            
Response.Write("alert('hi')");显示在页面上    
</form>
Response.Write("alert('hi')");显示在页面上 
</body>
Response.Write("alert('hi')");显示在页面上
</html>

cs页面:
Response.Write("alert('hi')");显示在页面上using System;
Response.Write("alert('hi')");显示在页面上
using System.Data;
Response.Write("alert('hi')");显示在页面上
using System.Configuration;
Response.Write("alert('hi')");显示在页面上
using System.Collections;
Response.Write("alert('hi')");显示在页面上
using System.Web;
Response.Write("alert('hi')");显示在页面上
using System.Web.Security;
Response.Write("alert('hi')");显示在页面上
using System.Web.UI;
Response.Write("alert('hi')");显示在页面上
using System.Web.UI.WebControls;
Response.Write("alert('hi')");显示在页面上
using System.Web.UI.WebControls.WebParts;
Response.Write("alert('hi')");显示在页面上
using System.Web.UI.HtmlControls;
Response.Write("alert('hi')");显示在页面上
Response.Write("alert('hi')");显示在页面上
public partial class temp : System.Web.UI.Page

相关文章: