仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1020|回复: 8
打印 上一主题 下一主题

[学习教程] ASP.NET网页设计初学ASP.Net时备忘

[复制链接]
若相依 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:35:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
我实在想不明白java的机制,为什么非要那么蛋疼,在同一个平台下重复编译。asp.net|初学1.翻开新的窗口并传送参数:传送参数:
response.write("<script>window.open(*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+")</script>")
吸收参数:
stringa=Request.QueryString("id");
stringb=Request.QueryString("id1");

2.为按钮增加对话框
Button1.Attributes.Add("onclick","returnconfirm(确认?)");
button.attributes.add("onclick","if(confirm(areyousure...?)){returntrue;}else{returnfalse;}")

3.删除表格选定纪录
intintEmpID=(int)MyDataGrid.DataKeys[e.Item.ItemIndex];
stringdeleteCmd="DELETEfromEmployeewhereemp_id="+intEmpID.ToString()
4.删除表格纪录告诫
privatevoidDataGrid_ItemCreated(Objectsender,DataGridItemEventArgse)
{
switch(e.Item.ItemType)
{
caseListItemType.Item:
caseListItemType.AlternatingItem:
caseListItemType.EditItem:
TableCellmyTableCell;
myTableCell=e.Item.Cells[14];
LinkButtonmyDeleteButton;
myDeleteButton=(LinkButton)myTableCell.Controls[0];
myDeleteButton.Attributes.Add("onclick","returnconfirm(您是不是断定要删除这条信息);");
break;
default:
break;
}
}

5.点击表格行链接另外一页
privatevoidgrdCustomer_ItemDataBound(objectsender,System.Web.UI.WebControls.DataGridItemEventArgse)
{
//点击表格翻开
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
e.Item.Attributes.Add("onclick","window.open(Default.aspx?id="+e.Item.Cells[0].Text+");");
}

双击表格毗连到另外一页
在itemDataBind事务中
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
stringOrderItemID=e.item.cells[1].Text;
...
e.item.Attributes.Add("ondblclick","location.href=../ShippedGrid.aspx?id="+OrderItemID+"");
}
双击表格翻开新一页
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
stringOrderItemID=e.item.cells[1].Text;
...
e.item.Attributes.Add("ondblclick","open(../ShippedGrid.aspx?id="+OrderItemID+")");
}
★出格注重:【?id=】处不克不及为【?id=】
6.表格超毗连传记递参数
<asp:HyperLinkColumnTarget="_blank"headertext="ID号"DataTextField="id"NavigateUrl="aaa.aspx?id=<%#DataBinder.Eval(Container.DataItem,"数据字段1")%>&name=<%#DataBinder.Eval(Container.DataItem,"数据字段2")%>/>

7.表格点击改动色彩
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onclick","this.style.backgroundColor=#99cc00;this.style.color=buttontext;this.style.cursor=default;");
}

写在DataGrid的_ItemDataBound里
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmou搜索引擎优化ver","this.style.backgroundColor=#99cc00;this.style.color=buttontext;
this.style.cursor=default;");
e.Item.Attributes.Add("onmou搜索引擎优化ut","this.style.backgroundColor=;this.style.color=;");
}
8.关于日期格局
日期格局设定
DataFormatString="{0:yyyy-MM-dd}"
我以为应当在itembound事务中
e.items.cell["你的列"].text=DateTime.Parse(e.items.cell["你的列"].text.ToString("yyyy-MM-dd"))
9.猎取毛病信息并到指定页面
不要利用Response.Redirect,而应当利用Server.Transfer
e.g
//inglobal.asax
protectedvoidApplication_Error(Objectsender,EventArgse){
if(Server.GetLastError()isHttpUnhandledException)
Server.Transfer("MyErrorPage.aspx");
//其他的非HttpUnhandledException非常交给ASP.NET本人处置就okay了:)
}
Redirect会招致post-back的发生从而丧失了毛病信息,以是页面导向应当间接在服务器端实行,如许就能够在毛病处置页
面失掉堕落信息并举行响应的处置

10.清空Cookie
Cookie.Expires=[DateTime];
Response.Cookies("UserName").Expires=0

11.自界说非常处置
//自界说非常处置类
usingSystem;
usingSystem.Diagnostics;
namespaceMyAppException
{
///<summary>
///从体系非常类ApplicationException承继的使用程序非常处置类。
///主动将非常内容纪录到WindowsNT/2000的使用程序日记
///</summary>
publicclassAppException:System.ApplicationException
{
publicAppException()
{
if(ApplicationConfiguration.EventLogEnabled)
LogEvent("呈现一个未知毛病。");
}
publicAppException(stringmessage)
{
LogEvent(message);
}
publicAppException(stringmessage,ExceptioninnerException)
{
LogEvent(message);
if(innerException!=null)
{
LogEvent(innerException.Message);
}
}
//日记纪录类
usingSystem;
usingSystem.Configuration;
usingSystem.Diagnostics;
usingSystem.IO;
usingSystem.Text;
usingSystem.Threading;
namespaceMyEventLog
{
///<summary>
///事务日记纪录类,供应事务日记纪录撑持
///<remarks>
///界说了4个日记纪录办法(error,warning,info,trace)
///</remarks>
///</summary>
publicclassApplicationLog
{
///<summary>
///将毛病信息纪录到Win2000/NT事务日记中
///<paramname="message">必要纪录的文本信息</param>
///</summary>
publicstaticvoidWriteError(Stringmessage)
{

WriteLog(TraceLevel.Error,message);
}

///<summary>
///将告诫信息纪录到Win2000/NT事务日记中
///<paramname="message">必要纪录的文本信息</param>
///</summary>
publicstaticvoidWriteWarning(Stringmessage)
{

WriteLog(TraceLevel.Warning,message);
}

///<summary>
///将提醒信息纪录到Win2000/NT事务日记中
///<paramname="message">必要纪录的文本信息</param>
///</summary>
publicstaticvoidWriteInfo(Stringmessage)
{
WriteLog(TraceLevel.Info,message);
}
///<summary>
///将跟踪信息纪录到Win2000/NT事务日记中
///<paramname="message">必要纪录的文本信息</param>
///</summary>
publicstaticvoidWriteTrace(Stringmessage)
{

WriteLog(TraceLevel.Verbose,message);
}

///<summary>
///格局化纪录到事务日记的文本信息格局
///<paramname="ex">必要格局化的非常工具</param>
///<paramname="catchInfo">非常信息题目字符串.</param>
///<retvalue>
///<para>格局后的非常信息字符串,包含非常内容和跟踪仓库.</para>
///</retvalue>
///</summary>
publicstaticStringFormatException(Exceptionex,StringcatchInfo)
{
StringBuilderstrBuilder=newStringBuilder();
if(catchInfo!=String.Empty)
{
strBuilder.Append(catchInfo).Append("
");
}
strBuilder.Append(ex.Message).Append("
").Append(ex.StackTrace);
returnstrBuilder.ToString();
}
///<summary>
///实践事务日记写进办法
///<paramname="level">要纪录信息的级别(error,warning,info,trace).</param>
///<paramname="messageText">要纪录的文本.</param>
///</summary>
privatestaticvoidWriteLog(TraceLevellevel,StringmessageText)
{

try
{
EventLogEntryTypeLogEntryType;
switch(level)
{
caseTraceLevel.Error:
LogEntryType=EventLogEntryType.Error;
break;
caseTraceLevel.Warning:
LogEntryType=EventLogEntryType.Warning;
break;
caseTraceLevel.Info:
LogEntryType=EventLogEntryType.Information;
break;
caseTraceLevel.Verbose:
LogEntryType=EventLogEntryType.SuccessAudit;
break;
default:
LogEntryType=EventLogEntryType.SuccessAudit;
break;
}

EventLogeventLog=newEventLog("Application",ApplicationConfiguration.EventLogMachineName,ApplicationConfiguration.EventLogSourceName);
//写进事务日记
eventLog.WriteEntry(messageText,LogEntryType);

}
catch{}//疏忽任何非常
}
}//classApplicationLog
}

12.Panel横向转动,纵向主动扩大
<asp:panelstyle="overflow-x:scroll;overflow-y:auto;"></asp:panel>

13.回车转换成Tab
<scriptlanguage="javascript"for="document"event="onkeydown">
if(event.keyCode==13&&event.srcElement.type!=button&&event.srcElement.type!=submit&&event.srcElement.type!=reset&&event.srcElement.type!=&&event.srcElement.type!=textarea);
event.keyCode=9;
</script>

http://dotnet.aspx.cc/exam/enter2tab.aspx

14.DataGrid超等毗连列
DataNavigateUrlField="字段名"DataNavigateUrlFormatString="http://xx/inc/delete.aspx?ID={0}"

15.DataGrid行随鼠标变色
privatevoidDGzf_ItemDataBound(objectsender,System.Web.UI.WebControls.DataGridItemEventArgse)
{
if(e.Item.ItemType!=ListItemType.Header)
{
e.Item.Attributes.Add("onmou搜索引擎优化ut","this.style.backgroundColor=""+e.Item.Style["BACKGROUND-COLOR"]+""");
e.Item.Attributes.Add("onmou搜索引擎优化ver","this.style.backgroundColor=""+"#EFF3F7"+""");
}

}

16.模板列
<ASP:TEMPLATECOLUMNvisible="False"sortexpression="demo"headertext="ID">
<ITEMTEMPLATE>
<ASP:LABELtext=<%#DataBinder.Eval(Container.DataItem,"ArticleID")%>runat="server"width="80%"id="lblColumn"/>
</ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>

<ASP:TEMPLATECOLUMNheadertext="选中">
<HEADERSTYLEwrap="False"horizontalalign="Center"></HEADERSTYLE>
<ITEMTEMPLATE>
<ASP:CHECKBOXid="chkExport"runat="server"/>
</ITEMTEMPLATE>
<EDITITEMTEMPLATE>
<ASP:CHECKBOXid="chkExportON"runat="server"enabled="true"/>
</EDITITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>
背景代码
protectedvoidCheckAll_CheckedChanged(objectsender,System.EventArgse)
{
//改动列的选定,完成全选或全不选。
CheckBoxchkExport;
if(CheckAll.Checked)
{
foreach(DataGridItemoDataGridIteminMyDataGrid.Items)
{
chkExport=(CheckBox)oDataGridItem.FindControl("chkExport");
chkExport.Checked=true;
}
}
else
{
foreach(DataGridItemoDataGridIteminMyDataGrid.Items)
{
chkExport=(CheckBox)oDataGridItem.FindControl("chkExport");
chkExport.Checked=false;
}
}
}
17.数字格局化
【<%#Container.DataItem("price")%>的了局是500.0000,如何格局化为500.00?】
<%#Container.DataItem("price","{0:¥#,##0.00}")%>
inti=123456;
strings=i.ToString("###,###.00");
18.日期格局化
【aspx页面内:<%#DataBinder.Eval(Container.DataItem,"Company_Ureg_Date")%>
显现为:2004-8-1119:44:28
我只想要:2004-8-11】
<%#DataBinder.Eval(Container.DataItem,"Company_Ureg_Date","{0:yyyy-M-d}")%>
应当怎样改?

【格局化日期】
掏出来,通常为object
((DateTime)objectFromDB).ToString("yyyy-MM-dd");

【日期的考证表达式】
A.以下准确的输出格局:[2004-2-29],[2004-02-2910:29:39pm],[2004/12/31]
^((d{2}(([02468][048])|([13579][26]))[-/s]?((((0?[13578])|(1[02]))[-/s]?((0?[1-9])|([1-2][0-9])|
(3[01])))|(((0?[469])|(11))[-/s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[-/s]?((0?[1-9])|([1-2][0-9])))))
|(d{2}(([02468][1235679])|([13579][01345789]))[-/s]?((((0?[13578])|(1[02]))[-/s]?((0?[1-9])|([1-2][0-9])
|(3[01])))|(((0?[469])|(11))[-/s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[-/s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(s(((0?[1-9])|(1[0-2])):([0-5][0-9])((s)|(:([0-5][0-9])s))([AM|PM|am|pm]{2,2})))?$
B.以下准确的输出格局:[0001-12-31],[99990930],[2002/03/03]
^d{4}[-/s]?((((0[13578])|(1[02]))[-/s]?(([0-2][0-9])|(3[01])))|(((0[469])|(11))[-/s]?(([0-2][0-9])|(30)))|(02[-/s]?[0-2][0-9]))$

【巨细写转换】
HttpUtility.HtmlEncode(string);
HttpUtility.HtmlDecode(string)
19.怎样设定全局变量
Global.asax中
Application_Start()事务中
增加Application[属性名]=xxx;
就是你的全局变量
20.如何作到HyperLinkColumn天生的毗连后,点击毗连,翻开新窗口?
HyperLinkColumn有个属性Target,将器值设置成"_blank"便可.(Target="_blank")
【ASPNETMENU】点击菜单项弹出新窗口
在你的menuData.xml文件的菜单项中到场URLTarget="_blank"
如:
<?xmlversion="1.0"encoding="GB2312"?>
<MenuDataImagesBaseURL="images/">
<MenuGroup>
<MenuItemLabel="内参信息"URL="Infomation.aspx">
<MenuGroupID="BBC">
<MenuItemLabel="通告信息"URL="Infomation.aspx"URLTarget="_blank"LeftIcon="file.gif"/>
<MenuItemLabel="体例信息简报"URL="NewInfo.aspx"LeftIcon="file.gif"/>
......
最好将你的aspnetmenu晋级到1.2版
21.托付会商
http://community.csdn.net/Expert/topic/2651/2651579.xml?temp=.7183191
http://dev.csdn.net/develop/article/22/22951.shtm
22.读取DataGrid控件TextBox值
foreach(DataGriddgiinyourDataGrid.Items)
{
TextBoxtb=(TextBox)dgi.FindControl("yourTextBoxId");
tb.Text....
}
23.在DataGrid中有3个模板列包括Textbox分离为DG_ShuLiang(数目)DG_DanJian(单价)DG_JinE(金额)分离在5.6.7列,请求在录进数目及单价的时分主动算出金额即:数目*单价=金额还请求录进时限定为数值型.我怎样用客户端剧本完成这个功效?
〖思回〗
<asp:TemplateColumnHeaderText="数目">
<ItemTemplate>
<asp:TextBoxid="ShuLiang"runat=serverText=<%#DataBinder.Eval(Container.DataItem,"DG_ShuLiang")%>
onkeyup="javascript:DoCal()"
/>
<asp:RegularExpressionValidatorid="revS"runat="server"ControlToValidate="ShuLiang"ErrorMessage="mustbeinteger"ValidationExpression="^d+$"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumnHeaderText="单价">
<ItemTemplate>
<asp:TextBoxid="DanJian"runat=serverText=<%#DataBinder.Eval(Container.DataItem,"DG_DanJian")%>
onkeyup="javascript:DoCal()"
/>
<asp:RegularExpressionValidatorid="revS2"runat="server"ControlToValidate="DanJian"ErrorMessage="mustbenumeric"ValidationExpression="^d+(.d*)?$"/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumnHeaderText="金额">
<ItemTemplate>
<asp:TextBoxid="JinE"runat=serverText=<%#DataBinder.Eval(Container.DataItem,"DG_JinE")%>/>
</ItemTemplate>
</asp:TemplateColumn>


<scriptlanguage="javascript">
functionDoCal()
{
vare=event.srcElement;
varrow=e.parentNode.parentNode;
vartxts=row.all.tags("INPUT");
if(!txts.length||txts.length<3)
return;

varq=txts[txts.length-3].value;
varp=txts[txts.length-2].value;
if(isNaN(q)||isNaN(p))
return;
q=parseInt(q);
p=parseFloat(p);
txts[txts.length-1].value=(q*p).toFixed(2);
}
</script>

24.datagrid选定对照底下的行时,为何老是革新一下,然后就转动到了最下面,方才选定的行因屏幕的干系就看不到了
page_load
page.smartNavigation=true
25.在Datagrid中修正数据,当点击编纂键时,数据呈现在文本框中,怎样把持文本框的巨细?
privatevoidDataGrid1_ItemDataBound(objsender,DataGridItemEventArgse)
{
for(inti=0;i<e.Item.Cells.Count-1;i++)
if(e.Item.ItemType==ListItemType.EditType)
{
e.Item.Cells.Attributes.Add("Width","80px")
}
}

26.对话框
privatestaticstringScriptBegin="<scriptlanguage="JavaScript">";
privatestaticstringScriptEnd="</script>";
publicstaticvoidConfirmMessageBox(stringPageTarget,stringContent)
{
stringConfirmContent="varretValue=window.confirm("+Content+");"+"if(retValue){window.location="+PageTarget+";}";

ConfirmContent=ScriptBegin+ConfirmContent+ScriptEnd;

PageParameterPage=(Page)System.Web.HttpContext.Current.Handler;
ParameterPage.RegisterStartupScript("confirm",ConfirmContent);
//Response.Write(strScript);

}
因为二次编译器太复杂,那么建议只是在安装程序的时候编译一次,而不类似java那样运行就编译。并且我觉得,一次痛苦,总比多次低效率要舒服多了。
admin 该用户已被删除
沙发
发表于 2015-1-17 21:01:19 | 只看该作者
那么,ASP.Net有哪些改进呢?
山那边是海 该用户已被删除
板凳
发表于 2015-1-21 07:54:14 | 只看该作者
市场决定一切,我个人从经历上觉得两者至少在很长时间内还是要共存下去,包括C和C++,至少从找工作就看得出来,总不可能大家都像所谓的时尚一样,追捧一门语言并应用它。
海妖 该用户已被删除
地板
发表于 2015-1-30 12:34:01 | 只看该作者
最强的技术支持WebService,而且有.NET的所有library做后盾。而且ASP.NET在.NET3.5中还有微软专门为AJAX开发的功能--ASP.NETAJAX。
透明 该用户已被删除
5#
发表于 2015-2-6 11:48:34 | 只看该作者
业务逻辑代码都不必做任何改动;继承性和多态性使得代码的可重用性大大提高,你可以通过继承已有的对象最大限度保护你以前的投资。并且C#和C++、Java一样提供了完善的调试/纠错体系。
活着的死人 该用户已被删除
6#
发表于 2015-2-16 02:29:49 | 只看该作者
我的意思是.net好用,从功能上来说比JAVA强还是很明显的。
飘飘悠悠 该用户已被删除
7#
发表于 2015-3-4 22:57:42 | 只看该作者
最强的技术支持WebService,而且有.NET的所有library做后盾。而且ASP.NET在.NET3.5中还有微软专门为AJAX开发的功能--ASP.NETAJAX。
第二个灵魂 该用户已被删除
8#
发表于 2015-3-11 21:17:03 | 只看该作者
ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp)。
若相依 该用户已被删除
9#
 楼主| 发表于 2015-3-28 05:08:23 | 只看该作者
Asp.net:首先来说,Asp.net和Asp没什么关系,看着像是升级版本什么的,其实没什么联系。Asp是脚本编程,用的是ASP语言,而ASP.net用的是C#语言,完全不同的东西。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-4-27 14:39

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表