网站访问者阅读重点在哪

by 崔志辉 13. August 2009 13:55

网站访问者阅读重点在哪(转载 比较有价值)

核心问题:首页布局

       视线多数时候常常首先在页面左上角停留,然后在该区域稍作浏览,跟着移动到页面右方。在对页面上方进行一段时间的仔细阅读后,眼球才会开始浏览下方内容。

[在这里查看Eyetrack III关于首页布局的更多观点]

醒目的标题常常在第一眼拉住人们——尤其是当标题位于左上方,更多时候位于右上方(但并非始终如此)时。

    与你所想的恰恰相反,图片不是首页的典型进入阅读点。不管是以阅读次序而论,还是以总阅读时间而论,文字都是PC屏幕的统治者

  我们观察到,对于网站首页,读者会本能地先看站点logo和左上角的标题。下图显示了从Eyetrack研究数据中计算出来的页面区域重要性分布。每个站点都不一样,也许你该检查自己的站点,看看在这些区域中,分别放置了什么内容。

 希望用户阅读而非一扫而过?考虑使用小字体

  在测试标题和首页字体时,Eyetrack III发现一些重要的现象:小字体使得人们集中精力阅读,而大字体则引致快速扫读。普遍而言,研究结果表明,人们花更多时间在小字体文字上。较大的字体导致更多的扫读——眼光只会在少数词上停留——人们四处乱看,寻找能抓住他们注意力的词或短语。
  (我不赞同,人们之所以一目十行,是因为网上的垃圾内容过多,充斥着大量废话,网站没有精辟的编辑)

对标题、导语的不完全浏览

  当人们阅读新闻页面上标题下的导语时,他们常常只看整个导语块的左边三分之一。也就是说,多数人只看头几个词——如果这几个词吸引了注意力,才会继续阅读。

  往往是标题的左边最受关注。典型阅读行为是眼光扫过标题列表,且常常不看整个标题。如果第一个词吸引了他们,通常会继续阅读。平均而言,一条标题耗费网站单个访问者不到一秒钟的时间。

对于标题——尤其是长标题——必须保证头几个词真的能吸引读者。

  对于那些首页长度超出第一屏的站点来说。Eyetrack III发现人们的确会阅读第一屏以下的页面。只不过,他们的眼光会扫过页面较下方,寻找吸引注意力的标题。如果看到有趣的标题或特别的词,眼光就会停留,不过不停留在内容块上。这又重申了写作简明标题的重要性。

[在这里查看Eyetrack III对于导语的研究]

[在这里这里阅读关于首页设计的研究成果]

你的导航在哪儿?

  上部、左边栏和右边栏?  
  放置于页面上部的导航栏效果最佳——在对25个顶级新闻站点的考查中,我们发现其中11个使用顶部导航条。其余14个使用左边栏导航。25个中的7个既在上部导航,又在左边导航。没有一个站点把导航元素放在右边栏。偶尔你会发现某些新闻站点也采用右边栏导航。

  让人惊奇的是,在研究中我们发现,右边栏导航反而更为有效——也许是因为人们不习惯在右边看到导航元素,所以较受关注——或者这能告诉我们,没有理由不把导航元素放到右边栏,而把左边栏留给编辑的内容或广告。

文章布局和写作风格又如何呢?

  研究结果表明,极具个性化的文章写作风格和布局较易吸引读者注意。 
  对25个新闻站点的考察结果表明,编辑常将段落砍到每段一个句子。
  研究结果表明,较短的段落比长段落表现更好。短段落得到的眼光聚焦比长段落要多一倍。长段落阻碍了阅读。

[在这里查阅关于文章布局的研究结果]

广告

  我们测试了多种首页/文章阅读页的广告位置和广告格式。

  最先注意到的是,人们经常忽略广告,但这取决于广告的放置。如果人们看一眼广告,则通常耗费0.5到1.5秒的时间。良好的放置和正确的格式能改进这个数字。

  我们发现,放置于首页上方和左边的广告,取得最多的眼光停留。右边的广告效果没那么好,页面底端的广告则往往只有很少一部分人会去看。

  尽可能地接近编辑过的内容,有助于广告获得阅读。我们注意到,当广告和内容区被空白区域或横条隔开时,会比没有隔开的广告受到更少的眼光停留。靠近页顶标题的广告表现良好。首页flag上方的Banner广告,不能取得与flag下方、编辑内容上方的Banner广告同样的吸引注意力效果。

  在我们测试过的所有类型的广告中,文字广告最能吸引阅读。在测试页面上,文字广告大约能获得7秒的平均眼光停留时间;而最好的图片/Flash广告只获得平均1.6秒眼光停留时间。

  尺寸影响注意力。较大尺寸的广告得到更多被看到机会。首页右边的小型广告只有1/3受试者会看;其余的人根 本连一眼都不会瞟。在文章阅读页面,"半页"广告是最容易为受试者注意的广告。但是,只有38%的人会去看它们,多数人根本不会看。最有可能被看到的是插 入正文的文字链广告。摩天大楼广告(页面左边或右边长而窄的垂直广告)位居第三。

[在这里阅读关于广告的研究结果]

大图片比小图片更能吸引眼球

  
尽管多数受试者不会在第一眼就看图片,我们还是观察到图片吸引了明显数量的眼光停留。我们还发现,图片越大,人们会花越多时间在上面。

  其中一个测试页面上,一块邮票大小的图片区域获得10%受试者的注意。而一幅平均大小的相片(约230x230象素)则获得了70%受试者的注意。

  我们发现,至少210x230象素大小的图片会获得超过一半受试者的注意。测试结果还说明,较干净的图片较易让眼光停留。

  文章阅读页面也是如此,较大图片较易引起注意。

  还有个花絮:我们发现人们经常会点击图片——即便测试页面的图片没有链接到任何地方

[在这里阅读Eyetrack III关于图片的研究结果]

[在这里阅读Eyetrack III关于多媒体的研究,也可以进一步阅读附加的综合多媒体观察]

 

Tags:

总结的在ASP.NET中常使用的三十三种代码

by 崔志辉 22. July 2009 10:35

1. 打开新的窗口并传送参数:

传送参数:

response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>")

接收参数:

string a = Request.QueryString("id");

string b = Request.QueryString("id1");

 

2.为按钮添加对话框

Button1.Attributes.Add("onclick","return confirm('确认?')");

button.attributes.add("onclick","if(confirm('are you sure...?')){return true;}else{return false;}")

 

3.删除表格选定记录

int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex];

string deleteCmd = "Delete from Employee where emp_id = " + intEmpID.ToString()

 

4.删除表格记录警告

private void DataGrid_ItemCreated(Object sender,DataGridItemEventArgs e)

{

 switch(e.Item.ItemType)

 {

  case ListItemType.Item :

  case ListItemType.AlternatingItem :

  case ListItemType.EditItem:

   TableCell myTableCell;

   myTableCell = e.Item.Cells[14];

   LinkButton myDeleteButton ;

   myDeleteButton = (LinkButton)myTableCell.Controls[0];

   myDeleteButton.Attributes.Add("onclick","return confirm('您是否确定要删除这条信息');");

   break;

   default:

   break;

 }

}

 

5.点击表格行链接另一页

private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)

{

 //点击表格打开

 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)

{

 string orderItemID =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)

{

 string orderItemID =e.item.cells[1].Text;

 ...

 e.item.Attributes.Add("ondblclick", "open('../ShippedGrid.aspx?id=" + orderItemID + "')");

}

 

6.表格超连接列传递参数

<asp:HyperLinkColumn Target="_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("onmouseover","this.style.backgroundColor='#99cc00';

   this.style.color='buttontext';this.style.cursor='default';");

e.Item.Attributes.Add("onmouseout","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

// in global.asax

protected void Application_Error(Object sender, EventArgs e) {

if (Server.GetLastError() is HttpUnhandledException)

Server.Transfer("MyErrorPage.aspx");

//其余的非HttpUnhandledException异常交给ASP.NET自己处理就okay了 :)

}

  Redirect会导致post-back的产生从而丢失了错误信息,所以页面导向应该直接在服务器端执行,这样就可以在错误处理页面得到出错信息并进行相应的处理

10.清空Cookie

Cookie.Expires=[DateTime];

Response.Cookies("UserName").Expires = 0

    

11.自定义异常处理

//自定义异常处理类

using System;

using System.Diagnostics;

namespace MyAppException

{

 /// <summary>

 /// 从系统异常类ApplicationException继承的应用程序异常处理类。

 /// 自动将异常内容记录到Windows NT的应用程序日志

 /// </summary>

 public class AppException:System.ApplicationException

 {

  public AppException()

  {

   if (ApplicationConfiguration.EventLogEnabled)LogEvent("出现一个未知错误。");

  }

 public AppException(string message)

 {

  LogEvent(message);

 }

 public AppException(string message,Exception innerException)

 {

  LogEvent(message);

  if (innerException != null)

  {

   LogEvent(innerException.Message);

  }

 }

 //日志记录类

 using System;

 using System.Configuration;

 using System.Diagnostics;

 using System.IO;

 using System.Text;

 using System.Threading;

 namespace MyEventLog

 {

  /// <summary>

  /// 事件日志记录类,提供事件日志记录支持

  /// <remarks>

  /// 定义了4个日志记录方法 (error, warning, info, trace)

  /// </remarks>

  /// </summary>

  public class ApplicationLog

  {

   /// <summary>

   /// 将错误信息记录到WinNT事件日志中

   /// <param name="message">需要记录的文本信息</param>

   /// </summary>

   public static void WriteError(String message)

   {

    WriteLog(TraceLevel.Error, message);

   }

   /// <summary>

   /// 将警告信息记录到WinNT事件日志中

   /// <param name="message">需要记录的文本信息</param>

   /// </summary>

   public static void WriteWarning(String message)

   {

    WriteLog(TraceLevel.Warning, message);  

   }

   /// <summary>

   /// 将提示信息记录到WinNT事件日志中

   /// <param name="message">需要记录的文本信息</param>

   /// </summary>

   public static void WriteInfo(String message)

   {

    WriteLog(TraceLevel.Info, message);

   }

   /// <summary>

   /// 将跟踪信息记录到WinNT事件日志中

   /// <param name="message">需要记录的文本信息</param>

   /// </summary>

   public static void WriteTrace(String message)

   {

    WriteLog(TraceLevel.Verbose, message);

   }

   /// <summary>

   /// 格式化记录到事件日志的文本信息格式

   /// <param name="ex">需要格式化的异常对象</param>

   /// <param name="catchInfo">异常信息标题字符串.</param>

   /// <retvalue>

   /// <para>格式后的异常信息字符串,包括异常内容和跟踪堆栈.</para>

   /// </retvalue>

   /// </summary>

   public static String FormatException(Exception ex, String catchInfo)

   {

    StringBuilder strBuilder = new StringBuilder();

    if (catchInfo != String.Empty)

    {

     strBuilder.Append(catchInfo).Append("\r\n");

    }

    strBuilder.Append(ex.Message).Append("\r\n").Append(ex.StackTrace);

    return strBuilder.ToString();

   }

   /// <summary>

   /// 实际事件日志写入方法

   /// <param name="level">要记录信息的级别(error,warning,info,trace).</param>

   /// <param name="messageText">要记录的文本.</param>

   /// </summary>

   private static void WriteLog(TraceLevel level, String messageText)

   {

    try

    {

     EventLogEntryType LogEntryType;

     switch (level)

     {

      case TraceLevel.Error:

       LogEntryType = EventLogEntryType.Error;

       break;

      case TraceLevel.Warning:

       LogEntryType = EventLogEntryType.Warning;

       break;

      case TraceLevel.Info:

       LogEntryType = EventLogEntryType.Information;

       break;

      case TraceLevel.Verbose:

       LogEntryType = EventLogEntryType.SuccessAudit;

       break;

      default:

       LogEntryType = EventLogEntryType.SuccessAudit;

       break;

     }

     EventLog

eventLog = new EventLog("Application",

ApplicationConfiguration.EventLogMachineName,

ApplicationConfiguration.EventLogSourceName );

     //写入事件日志

     eventLog.WriteEntry(messageText, LogEntryType);

    }

   catch {} //忽略任何异常

  }

 } //class ApplicationLog

}

 

12.Panel 横向滚动,纵向自动扩展

<asp:panel style="overflow-x:scroll;overflow-y:auto;"></asp:panel>

    

13.回车转换成Tab

<script language="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>

onkeydown="if(event.keyCode==13) event.keyCode=9"

    

14.DataGrid超级连接列

DataNavigateUrlField="字段名" DataNavigateUrlFormatString="http://xx/inc/delete.aspx?ID={0}"

    

15.DataGrid行随鼠标变色

private void DGzf_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)

{

 if (e.Item.ItemType!=ListItemType.Header)

 {

  e.Item.Attributes.Add( "onmouseout","this.style.backgroundColor=\""+e.Item.Style["BACKGROUND-COLOR"]+"\"");

  e.Item.Attributes.Add( "onmouseover","this.style.backgroundColor=\""+ "#EFF3F7"+"\"");

 }

}

    

16.模板列

<ASP:TEMPLATECOLUMN visible="False" sortexpression="demo" headertext="ID">

<ITEMTEMPLATE>

<ASP:LABEL text='<%# DataBinder.Eval(Container.DataItem, "ArticleID")%>' runat="server" width="80%" id="lblColumn" />

</ITEMTEMPLATE>

</ASP:TEMPLATECOLUMN>

<ASP:TEMPLATECOLUMN headertext="选中">

<HEADERSTYLE wrap="False" horizontalalign="Center"></HEADERSTYLE>

<ITEMTEMPLATE>

<ASP:CHECKBOX id="chkExport" runat="server" />

</ITEMTEMPLATE>

<EDITITEMTEMPLATE>

<ASP:CHECKBOX id="chkExportON" runat="server" enabled="true" />

</EDITITEMTEMPLATE>

</ASP:TEMPLATECOLUMN>

  后台代码

protected void CheckAll_CheckedChanged(object sender, System.EventArgs e)

{

 //改变列的选定,实现全选或全不选。

 CheckBox chkExport ;

 if( CheckAll.Checked)

 {

  foreach(DataGridItem oDataGridItem in MyDataGrid.Items)

  {

   chkExport = (CheckBox)oDataGridItem.FindControl("chkExport");

   chkExport.Checked = true;

  }

 }

 else

 {

  foreach(DataGridItem oDataGridItem in MyDataGrid.Items)

  {

   chkExport = (CheckBox)oDataGridItem.FindControl("chkExport");

   chkExport.Checked = false;

  }

 }

}

    

17.数字格式化

  【<%#Container.DataItem("price")%>的结果是500.0000,怎样格式化为500.00?】

<%#Container.DataItem("price","{0:¥#,##0.00}")%>

int i=123456;

string s=i.ToString("###,###.00");

 

18.日期格式化

  【aspx页面内:<%# DataBinder.Eval(Container.DataItem,"Company_Ureg_Date")%>

  显示为: 2004-8-11 19: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-29 10:29:39 pm], [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], [9999 09 30], [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",如:

<?xml version="1.0" encoding="GB2312"?>

<MenuData ImagesBaseURL="images/">

<MenuGroup>

<MenuItem Label="内参信息" URL="Infomation.aspx" >

<MenuGroup ID="BBC">

<MenuItem Label="公告信息" URL="Infomation.aspx" URLTarget="_blank" LeftIcon="file.gif"/>

<MenuItem Label="编制信息简报" URL="NewInfo.aspx" LeftIcon="file.gif" />

......

  最好将你的aspnetmenu升级到1.2版

    

21.读取DataGrid控件TextBox值

foreach(DataGrid dgi in yourDataGrid.Items)

{

 TextBox tb = (TextBox)dgi.FindControl("yourTextBoxId");

 tb.Text....

}

    

23.在DataGrid中有3个模板列包含Textbox分别为 DG_ShuLiang (数量) DG_DanJian(单价) DG_JinE(金额)分别在5.6.7列,要求在录入数量及单价的时候自动算出金额即:数量*单价=金额还要求录入时限制为 数值型.我如何用客户端脚本实现这个功能?

<asp:TemplateColumn HeaderText="数量">

<ItemTemplate>

<asp:TextBox id="ShuLiang" runat='server' Text='<%# DataBinder.Eval(Container.DataItem,"DG_ShuLiang")%>'

onkeyup="javascript:DoCal()"

/>

<asp:RegularExpressionValidator

id="revS" runat="server" ControlToValidate="ShuLiang"

ErrorMessage="must be integer" ValidationExpression="^\d+$" />

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="单价">

<ItemTemplate>

<asp:TextBox id="DanJian" runat='server' Text='<%# DataBinder.Eval(Container.DataItem,"DG_DanJian")%>'

onkeyup="javascript:DoCal()"

/>

<asp:RegularExpressionValidator

id="revS2" runat="server" ControlToValidate="DanJian"

ErrorMessage="must be numeric" ValidationExpression="^\d+(\.\d*)?$" />

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="金额">

<ItemTemplate>

<asp:TextBox id="JinE" runat='server' Text='<%# DataBinder.Eval(Container.DataItem,"DG_JinE")%>' />

</ItemTemplate>

</asp:TemplateColumn><script language="javascript">

function DoCal()

{

 var e = event.srcElement;

 var row = e.parentNode.parentNode;

 var txts = row.all.tags("INPUT");

 if (!txts.length || txts.length < 3)

  return;

 var q = txts[txts.length-3].value;

 var p = 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中修改数据,当点击编辑键时,数据出现在文本框中,怎么控制文本框的大小 ?

 

private void DataGrid1_ItemDataBound(obj sender,DataGridItemEventArgs e)

{

 for(int i=0;i<e.Item.Cells.Count-1;i++)

  if(e.Item.ItemType==ListItemType.EditType)

  {

   e.Item.Cells[i].Attributes.Add("Width", "80px")

  }

}

26.对话框

private static string ScriptBegin = "<script language=\"JavaScript\">";

private static string ScriptEnd = "</script>";

public static void ConfirmMessageBox(string PageTarget,string Content)

{

 string ConfirmContent="var retValue=window.confirm('"+Content+"');"+"if(retValue){window.location='"+PageTarget+"';}";

 ConfirmContent=ScriptBegin + ConfirmContent + ScriptEnd;

 Page ParameterPage = (Page)System.Web.HttpContext.Current.Handler;

 ParameterPage.RegisterStartupScript("confirm",ConfirmContent);

 //Response.Write(strScript);

}

27. 将时间格式化:string aa=DateTime.Now.ToString("yyyy年MM月dd日");

  1.1 取当前年月日时分秒

currentTime=System.DateTime.Now;

  1.2 取当前年

int 年= DateTime.Now.Year;

  1.3 取当前月

int 月= DateTime.Now.Month;

  1.4 取当前日

int 日= DateTime.Now.Day;

  1.5 取当前时

int 时= DateTime.Now.Hour;

  1.6 取当前分

int 分= DateTime.Now.Minute;

  1.7 取当前秒

int 秒= DateTime.Now.Second;

  1.8 取当前毫秒

int 毫秒= DateTime.Now.Millisecond;

28.自定义分页代码:

  先定义变量 :

public static int pageCount; //总页面数

public static int curPageIndex=1; //当前页面

  下一页:

if(DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1))

{

 DataGrid1.CurrentPageIndex += 1;

 curPageIndex+=1;

}

bind(); // DataGrid1数据绑定函数

  上一页:

if(DataGrid1.CurrentPageIndex >0)

{

 DataGrid1.CurrentPageIndex += 1;

 curPageIndex-=1;

}

bind(); // DataGrid1数据绑定函数

  直接页面跳转:

int a=int.Parse(JumpPage.Value.Trim());//JumpPage.Value.Trim()为跳转值

if(a<DataGrid1.PageCount)

{

 this.DataGrid1.CurrentPageIndex=a;

}

bind();

 

29.DataGrid使用:

  添加删除确认:

private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)

{

 foreach(DataGridItem di in this.DataGrid1.Items)

 {

  if(di.ItemType==ListItemType.Item||di.ItemType==ListItemType.AlternatingItem)

  {

   ((LinkButton)di.Cells[8].Controls[0]).Attributes.Add("onclick","return confirm('确认删除此项吗?');");

  }

 }

}

  样式交替:

ListItemType itemType = e.Item.ItemType;

if (itemType == ListItemType.Item )

{

 e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#FFFFFF';";

 e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#d9ece1';cursor='hand';" ;

}

else if( itemType == ListItemType.AlternatingItem)

{

 e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#a0d7c4';";

 e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#d9ece1';cursor='hand';" ;

}

  添加一个编号列:

DataTable dt= c.ExecuteRtnTableForAccess(sqltxt); //执行sql返回的DataTable

DataColumn dc=dt.Columns.Add("number",System.Type.GetType("System.String"));

for(int i=0;i<dt.Rows.Count;i++)

{

 dt.Rows[i]["number"]=(i+1).ToString();

}

DataGrid1.DataSource=dt;

DataGrid1.DataBind();

  DataGrid1中添加一个CheckBox,页面中添加一个全选框

private void CheckBox2_CheckedChanged(object sender, System.EventArgs e)

{

 foreach(DataGridItem thisitem in DataGrid1.Items)

 {

  ((CheckBox)thisitem.Cells[0].Controls[1]).Checked=CheckBox2.Checked;

 }

}

  将当前页面中DataGrid1显示的数据全部删除

foreach(DataGridItem thisitem in DataGrid1.Items)

{

 if(((CheckBox)thisitem.Cells[0].Controls[1]).Checked)

 {

  string strloginid= DataGrid1.DataKeys[thisitem.ItemIndex].ToString();

  Del (strloginid); //删除函数

 }

}

    

30.当文件在不同目录下,需要获取数据库连接字符串(如果连接字符串放在Web.config,然后在Global.asax中初始化)

  在Application_Start中添加以下代码:

Application["ConnStr"]=this.Context.Request.PhysicalApplicationPath+ConfigurationSettings.

   AppSettings["ConnStr"].ToString();

    

31. 变量.ToString()

  字符型转换 转为字符串

12345.ToString("n"); //生成 12,345.00

12345.ToString("C"); //生成 ¥12,345.00

12345.ToString("e"); //生成 1.234500e+004

12345.ToString("f4"); //生成 12345.0000

12345.ToString("x"); //生成 3039 (16进制)

12345.ToString("p"); //生成 1,234,500.00%

    

32、变量.Substring(参数1,参数2);

  截取字串的一部分,参数1为左起始位数,参数2为截取几位。 如:string s1 = str.Substring(0,2);

    

33.在自己的网站上登陆其他网站:(如果你的页面是通过嵌套方式的话,因为一个页面只能有一个FORM,这时可以导向另外一个页面再提交登陆信息)

<SCRIPT language="javascript">

<!--

 function gook(pws)

 {

  frm.submit();

 }

//-->

</SCRIPT> <body leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">

<form name="frm" action=" http://220.194.55.68:6080/login.php?retid=7259 " method="post">

<tr>

<td>

<input id="f_user" type="hidden" size="1" name="f_user" runat="server">

<input id="f_domain" type="hidden" size="1" name="f_domain" runat="server">

<input class="box" id="f_pass" type="hidden" size="1" name="pwshow" runat="server">

<INPUT id="lng" type="hidden" maxLength="20" size="1" value="5" name="lng">

<INPUT id="tem" type="hidden" size="1" value="2" name="tem">

</td>

</tr>

</form>

  文本框的名称必须是你要登陆的网页上的名称,如果源码不行可以用vsniffer 看看。

  下面是获取用户输入的登陆信息的代码:

string name;

name=Request.QueryString["EmailName"];

try

{

 int a=name.IndexOf("@",0,name.Length);

 f_user.Value=name.Substring(0,a);

 f_domain.Value=name.Substring(a+1,name.Length-(a+1));

 f_pass.Value=Request.QueryString["Psw"];

}

catch

{

 Script.Alert("错误的邮箱!");

 Server.Transfer("index.aspx");

}

Tags:

简单学会Ajax中的UpdatePanel局部更新应用

by 崔志辉 20. July 2009 15:41

首先介绍一下Ajax

AJAX全称为"Asynchronous JavaScript and XML"(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术。在基于数据的应用中,用户需求的数据如联系人列表,可以从独立于实际网页的服务端取得并且可以被动态地写入网页中,给缓慢的Web应用体验着色使之像桌面应用一样。 虽然大部分开发人员在过去使用过XMLHttp或者使用Iframe来加载数据,但仅到现在我们才看到传统的开发人员和公司开始采用这些技术。就像新的编程语言或模型伴随着更多的痛苦,开发人员需要学习新的技巧及如何最好利用这些新技术。而UpdatePanel就是Ajax里面一个重要的可以实现局部更新功能的控件!

UpdatePanel的几个重要属性

UpdatePanel是一个控件面板,它往往充当一个容器,它的主要功能就是实现Web页面的局部刷新,而不是整页刷新。从而大大提高浏览速度,节省资源。

UpdatePanel控件的使用非常简单,它主要有以下几个重要属性:

名称

说明

ContentTemplate

内容模板,用户可以再模板中放置控件,HTML代码等内容

UpdateMode

更新模式

ChildrenAsTriggers

当控件回发到服务器时,是否更新

Triggers

UpdatePanelTrigger对象的集合

 

UpdateMode属性指定UpdatePanel的更新模式,值可以为Always或Conditional,默认为Always。默认情况下,Web页面有控件回发到服务器时,UpdatePanel总更新其内容。如果想手动控制UpdarePanel的内容,应把UpdateMode值设为Conditional。如图:

当一个Web窗体内存在多个UpdatePanel时,ChildrenAsTriggers可以指定UpdatePanel内部控件的回发是否影响UpdatePanel的更新。值可以为true或false,默认为true。

Tirrger属性可以指定一个集合,用户可以再该集合中添加实现局部更新的AsyncPostBackTrigger和实现整页更新的PostBackTrigger。如图:

外部的UpdatePanel的更新都将引起嵌套在内的UpdatePanel的更新,而嵌套在内部的UpdatePanel的更新不会影响外部的UpdatePanel的更新。如图:

而嵌套在内部的多个UpdatePanel之间的更新不会互相影响。如图:

一些基本代码:

<asp:UpdatePanel ID="uppDateTime3" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">

<ContentTemplate>

<fieldset class="FiledSet">

<legend style="text-align: left">UpdatePanel3:</legend>

<asp:Label ID="lblDateTime3" runat="server" Text=""></asp:Label>

<br />

<asp:Button ID="btnDateTime3" runat="server" Text="更新3" />

<asp:Button ID="btnDateTime4" runat="server" Text="更新4" />

<asp:Button ID="btnDateTime5" runat="server" Text="更新5" />

</fieldset>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTrigger ControlID="btnDateTime4" EventName="Click" />

<asp:PostBackTrigger ControlID="btnDateTime5" />

</Triggers>

</asp:UpdatePanel>

Tags:

CSS在IE和Firefox中的差异解决总结

by 崔志辉 20. July 2009 11:13

css在不同浏览器下显示效果不同

Firefox和IE对某些css样式的认定有不少区别,包括:

  • ul和ol的默认padding值是不一样的,在Firefox中,padding-left默认值为40px左右,而IE中为0,一般设置ul{margin:0;padding:0;}就能解决大部分问题
  • 对字体大小small的定义不同,Firefox中为13px,而IE中为16px,差别挺大,也只能设置为14px了事;(暂时没有发现)
  • 并列排列的多个元素(图片或者链接)的代码中的空格和回车会造成元素之间的间隙,而在Firefox中和在IE中显示是不一样的,IE显示空格(约8px)、Firefox显示空格(约4px)
  • 对不规范代码的兼容情况不同,IE中漏掉的关闭符号对显示不造成影响,而Firefox中就会形成错乱的布局,而在IE中用到的padding和margin的负值都会被Firefox解析为0,易造成布局的混乱;(我觉得好像负值在Firefox中也是有显示的)
  • Firefox对于长高尺寸的严格解析会造成与设置不匹配(超出)的图片或表格将原设置div撑大;
  • !important属性可以在除IE浏览器的其他浏览器中起作用,因此有人利用这种差别来令一个CSS兼容多种浏览器;
  • 未定义id的div,在IE中会与div属性中的其他设置有关,而在Firefox中的位置会于div在文件中位置有关,紧随前一个div出现……(有待尝试)
  • 设置为float的div在IE下设置的margin会加倍的,特别是margin-left,这是ie6的一个bug。解决的方法是在这个div里面加上display:inline;
  • 如果是动态地添加内容,高度最好不要定义。浏览器可以自动伸缩,然而如果是静态的内容,高度最好定好。(似乎有时候不会自动往下撑开,不知道具体怎么回事)
  • FF: div 设置 margin-left, margin-right 为 auto 时已经居中, IE 不行。IE里设置text-align:center,就居中了,但在FF中不行。所以一般两个都要设置。
  • FF: 设置 padding 后, div 会增加 height 和 width, 但 IE 不会, 故需要用 !important 多设一个 height 和 width(也没感觉,觉得设了padding,大家的高宽都变了)
  • 在FF中可以实现的div 垂直居中问题: vertical-align:middle; 将行距增加到和整个DIV一样高 line-height:200px; 然后插入文字,就垂直居中了。缺点是要控制内容不要换行。这种方法在IE中实现不了。(已试过!有用)
  • FF: 链接加边框和背景色,需设置 display: block, 同时设置 float: left 保证不换行。
  • 在浮动(float)的div后加clear属性,这可以解决背景的自适应高度问题。怎么加才能让不同浏览器都好使?IE中有默认行高,这是要解决的问题。
  • FF中不支持文字的自动转行;什么word-wrap:break-word;word-break:break-all都是IE搞的鬼,根本就不符合css标准。(现在看到的解决办法都是通过编程实现)

css解决不同浏览器的兼容问题的方法 (不是我们需要的方法,我们要达到的要求是尽量不写!important也能解决)

解决这种问题可以通过规范css代码,使其符合两种规范的标准样式,也可以在差别处利用!important对Firefox设置属性,或者针对多种浏览器分别各自配置合适的CSS文件,再通过判断浏览器选择不同CSS实现兼容性。

代码如下:

<!--[endif]-->

<!--[endif]-->

#example { color: #333; } /* FF*/

* html #example { color: #666; } /* IE6 */

*+html #example { color: #999; } /* IE7 */

这样在IE6中显示字体颜色是#666;在IE7中显示的字体颜色是#999;在FF中显示的颜色是#333

FF解决背景的自适应高度问题

①对于背景不能自动延伸的原因上面说的很清楚,解决方法是多嵌套一个层,这个层设置浮动,并承担背景,就ok了。

float使得层自动获得宽和高

但是有了第三种方法,这种方法好像并不值得推荐。

②另一种方法就是给第一个div赋予属性值:display:table;但这种方法会造成另外一些布局上的错误。可以考虑使用,但不建议使用。

③我想这是最重要的一种方法,但是中间问题很多。方法就是clear:both。

.clear{clear:both}可以使高度向下延续,但是会自动产生行高;

.clear{clear:both;height:0}在FF中清除了行高,但是IE里不认;

.clear{clear:both;height:1%}在FF和IE中仍然不认;

像之前写的.clear{clear:both;height:1%;font-size:0px;overflow:hidden}在IE中好使,但在FF中却不能让背景颜色延续,除非加上边框。!挺有意思,还是不太懂

.clear{clear:both;line-height:1px}好使!我理解是清的这个容器默认是行元素,所以高对它不起作用,所以你无论把height设置为几都没有效果,而line-height本身就是作用于行元素的,所以好使!

上面理解的不对!重新理解是:IE里面有默认的行高,必须把行高给清掉,可以用font-size:0px或line-height:0px;但是这里又有一个问题,就是height的值不要用百分数,没有用!

Tags:

Copyright © 2009 APJ Software

最新评论

Comment RSS

公告

欢迎使用APJ Blog!

日历

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar