ASPX頁顯示數據的兩種辦法【公共變量或者方法】以及對數據的渲染


 1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>
 2 
 3 <!DOCTYPE html>
 4 
 5 <html xmlns="http://www.w3.org/1999/xhtml">
 6 <head runat="server">
 7     <title></title>
 8     <style type="text/css">
 9         .content-href{
10             color:red;font-size:large;
11         }
12     </style>
13 </head>
14 <body>
15     <form id="form1" runat="server">
16     <div>
17         <input runat="server" id="btn" type="button" value="OK"/>
18     </div>
19     <div id="content" runat="server">
20         <a  class="content-href" href="http://www.baidu.com"><%=contentHTML %>的網址是:<%=getHTML() %></a>
21     </div>
22     </form>
23 </body>
24 </html>
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 
 8 public partial class index : System.Web.UI.Page
 9 {
10     public string contentHTML;
11     protected void Page_Load(object sender, EventArgs e)
12     {
13         if (!Page.IsPostBack)
14         {
15             //不涉及到客戶端頁面的代碼,放在這里可以保證不會重復執行         
16             //Speak();
17         }
18         //事件注冊的代碼放在這里比較好
19         btn.ServerClick += Say;
20     }
21     public void Speak()
22     {
23         string msg =  btn.Value;
24         Response.Write("<script type='text/javascript'>alert('"+msg+"')</script>");
25     }
26     public void Say(object hander,EventArgs e)
27     {
28         contentHTML = "百度";
29         Response.Write("<script type='text/javascript'>alert('Welcome to China!');</script>");
30     }
31     public string getHTML()
32     {
33         string tmp = "http://www.baidu.com/";
34         return tmp;
35     }
36 
37 }

 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com