自己写asp.net应用程序

一、登录的实现
      *Forms身份认证*
A)web.config
    <!-- Default.aspx 是登录页面-->
    <authentication mode="Forms">
        <forms name=".ASPXUSERDEMO" loginUrl="Default.aspx" protection="All" timeout="60" />
    </authentication>
    <!--configuration上增加节点,排除不需要导航到登录页面的页面。-->
    <location path="default.aspx">
         <system.web>
               <authorization>
                     <allow users="*" />
               </authorization>
         </system.web>
    </location>
B)用户名和密码验证成功后增加
   System.Web.Security.FormsAuthentication.RedirectFromLoginPage(用户名,false);
    Response.Redirect("Main.aspx",true);   //main.aspx是主窗口页面
C)获得用户标识
   string userid=System.Web.HttpContext.Current.User.Identity.Name;
D)登出
   System.Web.Security.FormsAuthentication.SignOut(); //登出
二、IEWebControl的用法
        *Toolbar客户端事件*
A)在工程中包含IEWebControl中的htc(如:toolbar.htc)
B)aspx页面
   <HTML XMLNS:td>
   <head>
   <?IMPORT NAMESPACE="tb" IMPLEMENTATION="htc/toolbar.htc"/>
   <script language="javascript">
  function toolbar_click()
  {
      var oButton = window.event.srcNode;
      var iButton = oButton.getAttribute("id");
      switch(iButton)
      {
         case 'add':
            f_add();
            break;
         case 'modify':
            f_modify();
            break;
         case 'delete':
               f_delete();
            break;
         case 'refresh':
            f_refresh();
            break;
        }
     }
  </script>
 </head>
 <body topMargin="0" MS_POSITIONING="GridLayout">
 <tb:TOOLBAR onbuttοnclick="toolbar_click()">  <!--  MOVEMENT="move-dock" -->
         <tb:TOOLBARGRIPPER/>
         <tb:TOOLBARBUTTON IMAGEURL="htc/images/root.gif" id="add" TEXT="新增"/>
         <tb:TOOLBARBUTTON id="modify" TEXT="修改"/>
         <tb:TOOLBARBUTTON id="delete" TEXT="删除"/>
         <tb:TOOLBARSEPARATOR/>
         <tb:TOOLBARBUTTON id="refresh" TEXT="刷新"/>
 </tb:TOOLBAR>
</body>
</html>
三、数据的展示
        *DataGrid改变选择行的颜色*
A).cs类
        private void DataGrid1_ItemDataBound(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
       {
            if(e.Item.ItemType != ListItemType.Header)
            {
              string fID = e.Item.Cells[1].Text;     // 这里的第一列为数据绑定中的ID值,通常是唯一标识    
              e.Item.Attributes.Add("id",fID);
              e.Item.Attributes.Add("onmouseover","sel('" + fID+ "')"); 
              e.Item.Attributes.Add("onclick", "clicktr('" + fID+"')");
             }
      }
B)aspx文件
       <script language="javascript">
         var oid;
         function sel(id) // 鼠标移上去后执行
        {
             document.getElementById(id).style.cursor='hand';
         }
        function clicktr(id)
       {
           if(typeof(oid) != 'undefined')
          {
              document.getElementById(oid).style.background='';
            }
     
            document.getElementById(id).style.background='#cccc66';
            oid = id;
         }
       </script>
四、无刷新的实现
        *Ajax的应用*
A)引用Ajax.dll
B)web.config的<system.web>中增加
 <!-- 对ajax支持  -->
 <httpHandlers>
  <add verb="POST,GET" path="ajax/*.ashx"  type="Ajax.PageHandlerFactory, Ajax" />
 </httpHandlers>
C)cs类的page_load()中增加
Ajax.Utility.RegisterTypeForAjax(typeof(类名));
D)cs类中增加有Ajax.AjaxMethod()属性的方法,如:
   [Ajax.AjaxMethod()]
  public string Delete(string id)
  {
      return;
  }
E)aspx文件脚本中增加调用方法和回调方法,如:
function f_delete()
  {
     if(typeof(oid) != 'undefined')
     {
        if(confirm("确定要删除吗?"))
        {
    类名.Delete(oid,f_delete_callback);
        }
     }
     else
     {
        alert("请选择要操作的行!");
     }
  }
  //回调函数
  function f_delete_callback(response)
  {
     if(response.error != null)
   {
    alert(response.error);
    return false;
   }
   var result = response.value;
      if(result != "")
      {
          alert("删除失败!");
      }
      else
      {
         alert("删除成功!");
         f_refresh();
      }
  }

CodeSmith 3.1 (.NET 1.1 / Visual Studio 2003)
http://www.codesmithtools.com/download.aspx?key=a33ea36cd0
JMail.Net 1.0(.NET 1.1)
http://www.cnblogs.com/files/hotsoho.net/jmailnetfree.zip
在线文本编辑器
http://www.lionsky.net/MyWebsite/downsoft/index.aspx

转载于:https://www.cnblogs.com/hotsoho.net/archive/2006/03/11/348137.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值