asp.net中形式的用法(原创)
2008-01-24 22:58
288 查看
今天第一天开通了博客,心情乐滋滋的,因为可以和园子里的朋友一起研究技术了。我希望把平时在项目中积累的知识以及自己学习的知识同园子里的朋友分享分享。为我们园子的壮大付出自己的一点努力。这是我发表的第二篇话题,希望对这<%%>语法不熟悉的朋友提供帮助,对已经熟悉的朋友,希望能提出你们宝贵的意见。
在asp.net中经常出现包含这种形式<%%>的html代码,我这里特别收集了,总的来说包含下面这样几种格式:
一. <%%>
这种格式实际上就是和asp的用法一样的,只是asp中里面是vbscript或者javascript代码,而在asp.net中是.net平台下支持的语言。
特别注意:服务器控件中不能有<%%>语法
(这里我用C#代码)
<div>
Server Control:<asp:TextBox ID="TextBox1" runat="server" Text="<%#text%>"></asp:TextBox><br /><!--Server Control-->
Client Control:<input type="text" id="textbox2" value="<%#text%>" /><!--Client Control-->
</div>
aspx.cs代码如下:
protected string text;//注意这里必须申明为public或protected,否则aspx页面(子类)无法访问
protected void Page_Load(object sender, EventArgs e)
<label id="label1"><%=DisplayStr()%></label><br />
<label id="label2" runat="server"><%=DisplayStr()%></label>
aspx.cs代码:
public string DisplayStr()//注意这里必须要有返回值,否则将会发生运行时错误
<asp:TextBox runat="server" ID="cc" Text="<%$ConnectionStrings:pubs%>"></asp:TextBox>
web.config文件如下:
<connectionStrings>
<add name="pubs" connectionString="Server=.;database=pubs;uid=sa;pwd=" providerName="System.Data.SqlClient"/>
</connectionStrings>
这样就能正常运行。
如果修改aspx中的文件:使用客户端的控件
<input type="text" value="<%$ConnectionStrings:pubs%>"/>
或者:不绑定到服务器控件的某个属性上
<asp:TextBox runat="server" ID="cc"><%$ConnectionStrings:pubs%></asp:TextBox>
运行都会出现相同的错误
最后注意一点:
<%#%>只针对的是服务器控件的数据绑定,因此不能同<%=%>和<%%>混合使用
转自:http://www.cnblogs.com/Charles2008/archive/2008/01/24/1051853.html
在asp.net中经常出现包含这种形式<%%>的html代码,我这里特别收集了,总的来说包含下面这样几种格式:
一. <%%>
这种格式实际上就是和asp的用法一样的,只是asp中里面是vbscript或者javascript代码,而在asp.net中是.net平台下支持的语言。
特别注意:服务器控件中不能有<%%>语法
(这里我用C#代码)
<div>
Server Control:<asp:TextBox ID="TextBox1" runat="server" Text="<%#text%>"></asp:TextBox><br /><!--Server Control-->
Client Control:<input type="text" id="textbox2" value="<%#text%>" /><!--Client Control-->
</div>
aspx.cs代码如下:
protected string text;//注意这里必须申明为public或protected,否则aspx页面(子类)无法访问
protected void Page_Load(object sender, EventArgs e)
<label id="label1"><%=DisplayStr()%></label><br />
<label id="label2" runat="server"><%=DisplayStr()%></label>
aspx.cs代码:
public string DisplayStr()//注意这里必须要有返回值,否则将会发生运行时错误
<asp:TextBox runat="server" ID="cc" Text="<%$ConnectionStrings:pubs%>"></asp:TextBox>
web.config文件如下:
<connectionStrings>
<add name="pubs" connectionString="Server=.;database=pubs;uid=sa;pwd=" providerName="System.Data.SqlClient"/>
</connectionStrings>
这样就能正常运行。
如果修改aspx中的文件:使用客户端的控件
<input type="text" value="<%$ConnectionStrings:pubs%>"/>
或者:不绑定到服务器控件的某个属性上
<asp:TextBox runat="server" ID="cc"><%$ConnectionStrings:pubs%></asp:TextBox>
运行都会出现相同的错误
最后注意一点:
<%#%>只针对的是服务器控件的数据绑定,因此不能同<%=%>和<%%>混合使用
转自:http://www.cnblogs.com/Charles2008/archive/2008/01/24/1051853.html
相关文章推荐
- asp.net中<%%>形式的用法(原创)
- asp.net中<%%>形式的用法(原创)
- asp.net中形式的用法
- asp.net中的<%%>形式的详细用法总结(转载)
- asp.net中的<%%>形式的详细用法总结
- asp.net中的<%%>形式的详细用法实例讲解
- asp.net中的<%%>的几种形式的用法
- asp.net中的<%%>形式的详细用法实例讲解
- asp.net中形式的用法
- asp.net中<%%>形式的用法(转帖)
- asp.net中形式的用法
- ASP.NET中形式的用法
- (转)asp.net中<%%>形式的用法
- asp.net Gridview用法大全 绝对原创
- asp.net中的<%%>的几种形式的用法
- [原创]共享一款ASP.NET验证码控件(附详细用法)
- ASP.NET中形式的用法
- asp.net中的<%%>形式的详细用法实例讲解
- asp.net中的<%%>形式的详细用法实例讲解
- asp.net中的<%%>形式的详细用法总结