用户操作
[即时聊天] [发私信] [加为好友]
福林天下ID:jdlsfl
30954次访问,排名3830(-1)好友113人,关注者148
软件
jdlsfl的文章
原创 92 篇
翻译 0 篇
转载 53 篇
评论 46 篇
福林天下的公告
If If you can keep your head when all about you Are losing theirs and blaming it on you; If you can trust yourself when all men doubt you, But make allowance for their doubting too; If you can wait and not be tired by waiting, Or, being lied about, don’t deal in lies, Or, being hated, don’t give way to hating, And yet don’t look too good, nor talk too wise; If you can dream - and not make dreams your master; If you can think - and not make thoughts your aim; If you can meet with triumph and disaster And treat those two impostors just the same; If you can bear to hear the truth you’ve spoken Twisted by knaves to make a trap for fools, Or watch the things you gave your life to broken, And stoop and build ’em up with 5)worn-out tools; If you can make one heap of all your winnings And risk it on one turn of pitch-and-toss, And lose, and start again at your beginnings And never breathe a word about your loss; If you can force your heart and nerve and sinew To serve your turn long after they are gone, And so hold on when there is nothing in you Except the Will which says to them: “Hold on !”; If you can talk with crowds and keep your virtue, Or walk with Kings - nor lose the common touch; If neither foes nor loving friends can hurt you; If all men count with you, but none too much; If you can fill the unforgiving minute With sixty seconds “worth of distance run”Yours is the Earth and everything that’s in it, And - which is more - you’ll be a Man !
最近评论
Randywei:good!
ut:4545
kaku88:論壇就是要有熱心的人才會茁壯, 感謝樓主了
everspring79:公司的架构师往往不具备架构师的基本知识储备和思路(这是最要命的),往往就从对产品最熟悉的人里面矮子里拔将军,顶多算领域专家,至于如何作出最具扩展性和封装特性的软件是毫无思路.
sap99:www.sap99.com/,SAP99资料多多

SAP免费资料下载
http://www.sap99.com

有很多的学习资料,推荐一下,
文章分类
收藏
    相册
    IT
    csdn(RSS)
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    转载 .Net环境下基于Ajax的MVC方案收藏

    新一篇: VS.NET 2005中实用的默认键,快捷键 | 旧一篇: .net工程师必懂的20道题

     1、问题背景

      现在,越来越多人开始尝试基于Ajax进行无刷新的Web开发,不过,在.Net环境下,应用Ajax并不是非常方便,这主要可能是由以下一些原因造成的:

      ·由于Ajax基于javascript的本质,使得开发者必须对javascript非常了解,起码,其javascript能力足以实现对callback返回内容对页面的更新,所以开发的门槛就有一定程度的上升

      ·当基于Ajax机制进行开发时,原有的基于postback方式下时,asp.net由后台逻辑代码(Model),aspx页面(View)、aspx.cs(Controller)构成的MVC构架其实失效了,当callback返回数据时,要么在client端用javascript解析返回内容以实现更新,要么则必须在server端构造好比较完整的html代码,再直接由javascript将该构造好的html设置给某个页面对象,很显然,这样一来,要实现一个最简单的callback功能,都要不少代码,并且是相对比较乱的代码,即使在即将到来的asp.net2.0该问题依然不会得到有效解决

      2、本文目的

      本文旨在充分利于现有的asp.net本身的特点和ajax的特性,提出一个用于在asp.net环境下进行基于ajax的web开发的MVC方案,以实现以下主要目的:

      ·Asp.Net环境下用于Ajax的清晰的MVC构架

      ·降低编程人员对过多javascript编码的依赖以降低编程门槛

      ·灵活的支持ajax模式下的常用开发方式

      3、问题分析

      如何实现以上几个主要目的呢?

     1)要对xmlhttprequest对更良好的封装,以使调用方式更简单;

     2)尽量在server端进行更新数据的构造,但是也要避免每次返回数据都手工构造,因此,就想到可以充分使用UserControl,由UserControl作为"View",对应的由ascx.cs文件作为"Controller",这样构成的MVC也是比较清晰的;
     
     4、问题解决

      基于以上思想,本人实现了以下一个组类库以简化该过程:

      源码及范例下载

      代码简析:

      1)首先在client端,AjaxHelper.js封装了xmlhttprequest,并提供一个将现有的<form>序列化为形如param1=v1&param2=v2&...形式用于post的参数;

      Updater(ajaxTemplate, output, params, onComplete)函数,用于实现一次callback调用

      ajaxTemplate(必选):指定执行需要功能的UserControl路径
      output(可选):填充返回数据的指定标签的引用或ID值
      params(可选):形如param1=v1&param2=v2&...的post参数
      onComplete(可选):可用于对返回数据进行特殊处理的回调函数,函数格式  function(str),str为返回的数据

      SerializeForm(form)函数,用于序列化<form>

      form:可以是对指定<form>的引用或ID值

      2)在server端,Ajax.aspx文件封装了对由客户端ajaxTemplate指定的UserControl的调用,其余的具体逻辑功能则在特定的UserControl及其ascx.cs内实现;

      3)这样,具体执行一次callback时,编程人员只需在页面引用AjaxHelper.js,并在指定的位置通过javascript:Updater(ajaxTemplate, output, params, onComplete)进行调用,如果需要对某一form进行提交,则可调用javascript:SerializeForm(form)序列化该form并传给params,当然也可以手动构造params,并指定将返回数据通过设置output应用的页面或通过onComplete自定义处理。

      4)由于充分使用UserControl,意味着,可以充分利用asp.net原有的web服务器端控件和数据绑定机制,这样其实,已经很大程度上简化了返回数据的构造,在ascx.cs中,通过Request.Form[ParamName]就能访问到client端传入的params,再访问逻辑代码获取源数据。

      5、范例

      包含在源码中的范例实现了一个简单的无刷新获取博客园首页内容到一个textarea的功能,详见源码! 

     部分范例源码:

      Default.aspx

     

    <%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="CN.Teddy.AjaxHelper.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
        
    <HEAD>
            
    <title>WebForm1</title>
            
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
            
    <meta name="CODE_LANGUAGE" Content="C#">
            
    <meta name="vs_defaultClientScript" content="JavaScript">
            
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
            
    <script type="text/javascript" language="javascript" src="js/AjaxHelper.js"></script>
        
    </HEAD>
        
    <body>
            
    <form id="Form1" method="post" runat="server">
                
    <div id="view2">loading</div>
                
    <script type="text/javascript">
                    Updater('AjaxTemplate
    /GetPageSrc', 'view2', 'url=http://www.cnblogs.com');
                
    </script>

            
    </form>
        
    </body>
    </HTML>


    AjaxHelper.js摘要:

    var AjaxHelperUrl = new String("Ajax.aspx");



    var Updater = function
    (ajaxTemplate, output, params, onComplete)

    {

        
    if (typeof output ==
     'string')

        {

            output 
    =
     $(output);

        }

        

        
    new Ajax.Request( 'Ajax.aspx', { onComplete: function(transport) { if (output != null) { output.innerHTML = FormatContent(transport.responseText); } if (onComplete != null) { onComplete(FormatContent(transport.responseText)) } }, parameters: params + '&AjaxTemplate=+
     ajaxTemplate });

    }



    var SerializeForm = function
    (form)

    {

        
    return
     Form.serialize(form);

    }



    var FormatContent = function
    (str)

    {

        
    var content = new
     String(str);

        
    var prefix = new String("<!--AjaxContent-->"
    );

        content 
    = content.substring(content.indexOf(prefix, 0+ prefix.length, content.length - 9
    );

        
    return
     content;

    }


    UserControl GetPageSrc.ascx.cs摘要:

            private void Page_Load(object sender, System.EventArgs e)
            
    {
                lbUrl.Text 
    = Request.Form["url"
    ];

                System.Net.WebClient client 
    = new
     System.Net.WebClient ();
                client.Headers.Add(
    "User-Agent""Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    );
                
    try

                
    {
                    txtPageSource.Text 
    = new
     System.IO.StreamReader(client.OpenRead(lbUrl.Text), System.Text.Encoding.UTF8).ReadToEnd();
                }

                
    catch(Exception ex)
                
    {
                    
    throw ex;
                }

            }

    发表于 @ 2007年12月08日 15:37:00|评论(loading...)|编辑

    新一篇: VS.NET 2005中实用的默认键,快捷键 | 旧一篇: .net工程师必懂的20道题

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © 福林天下