Page.ClientScript注册一个对JavaScript的code的 [英] Page.ClientScript Register a pair of javascript code

查看:193
本文介绍了Page.ClientScript注册一个对JavaScript的code的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何注册一个javascript code页?

How can I register a javascript code a page?

我想提出个<一个href=\"http://stackoverflow.com/questions/2897466/downloading-photos-on-the-client-side-every-10-seconds-on-an-ajax-enabled-asp-net\">javascript功能来的aspx.page;
我的事情可能是这样的;

I want to put th javascript function to the aspx.page; I thing it might be like that;

   string strJS= "<script language = javascript>

        (function(images, elements) {
            var fetchImages = function() {
                if(images.length > 0) {
                    var numImages = 10;
                    while(images.length > 0 && numImages-- > 0) {
                        // assuming your elements are <img>
                        document.getElementById(elements.shift()).src = images.shift();
                        // if not you could also set the background (or backgroundImage) css property
                        // document.getElementById(elements.shift()).style.background = "url(" + images.shift() + ")";
                    }
                    setTimeout(fetchImages, 5000);
                }
            }

            // bind to window onload
            window.onload = fetchImages;
            // if you're going to use something like jquery then do something like this instead
            //$(fetchImages);
        }(['url1', 'url2', 'url3'], ['img1', 'img2', 'img3'])) </script>";

Page.ClientScript.RegisterClientScriptBlock(typeof(ui_SUBMVGInfo), "SmartPenCheck", strJS);

第二Questin是;

  ...
... 
    g(ctrlIDBirthPlaceCode).onchange();

     }}
     </script>
     <script language = javascript>
     var url1 = 'http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_Adiniz';
     var url2 ='http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_Soyadiniz';
     var url3 = 'http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_tarih';
     var url4 = 'http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_Adiniz';
     var url5 ='http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_Soyadiniz';
     var url6 = 'http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_tarih';
     var url7 = 'http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_Adiniz';
     var url8 ='http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_Soyadiniz';
     var url9 = 'http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_tarih';
     var url10 = 'http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_Adiniz';
     var url11 ='http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_Soyadiniz';
     var url12 = 'http://localhost:3645/ImageHandler.ashx?FormId=XXX.11&FieldId=s1_tarih';
    function(images, elements) {var fetchImages = function() 
    {if(images.length > 0) {var numImages = 5;
    while(images.length > 0 && numImages-- > 0) { document.getElementById(elements.shift()).src = images.shift();
     }setTimeout(fetchImages, 5000);
    }}window.onload = fetchImages;
    }(['+url1+', '+url2+', '+url3+','+url4+', '+url5+', '+url6+','+url7+', '+url8+', '+url9+','+url10+', '+url11+', '+url12+'], ['ui_taskFormControl$ctl03$ctl00$ctl03$ui_CustomerNameImage', 'ui_taskFormControl$ctl03$ctl00$ctl03$ui_CustomerSurNameImage', 'ui_taskFormControl$ctl03$ctl00$ctl03$ui_MaritalStatusImage','ui_taskFormControl$ctl03$ctl00$ctl03$ui_SexImage','ui_taskFormControl$ctl03$ctl00$ctl03$ui_BirthDateImage','ui_taskFormControl$ctl03$ctl00$ctl03$ui_BirthPlaceCodeImage','ui_taskFormControl$ctl03$ctl00$ctl03$ui_BirthPlaceImage','ui_taskFormControl$ctl03$ctl00$ctl03$ui_IdNationalityImage','ui_taskFormControl$ctl03$ctl00$ctl03$ui_MotherOldSurNameImage','ui_taskFormControl$ctl03$ctl00$ctl03$ui_TaxNoImage','ui_taskFormControl$ctl03$ctl00$ctl03$ui_CitizenshipNoImage','ui_taskFormControl$ctl03$ctl00$ctl03$ui_HomePhoneImage']));
     </script>

     <script>
    var ui_BirthPlaceCode_a='Intertech.Utility';
    var ui_BirthPlaceCode_c='Intertech.Utility.Common';
    var ui_BirthPlaceCode_sbn='';
...
..

你觉得是还好吧或者我该怎么办呢?
根据上述第二个问题;使用code是正确的?
REF:<一href=\"http://stackoverflow.com/questions/2897466/downloading-photos-on-the-client-side-every-10-seconds-on-an-ajax-enabled-asp-net\">**

PS:看我的目的,请继续阅读下面的;

PS: To see my purpose please continue reading below;

有一个网站页面是
  在asp.net codeD使用C#和
  Ajax是启用了。

There is a web site page which is coded on asp.net with using c# and ajax is enabled too.

我想一个非常快速加载网页;
  这是会与发生
  以下架构;

I want a very fast loading web page; which is going to happen with the following architecture;

1-首先数据由文字显示
  盒(有50个文本框,它是
  一份申请表。)

1- First all data is shown by the text boxes (There are 50 text boxes, it is an application form.)

2 - 当被请求的网页,
  加载,那么我希望所有的照片都是
  附近的每个文本框10所表现出
  10从页面顶部,直到结束
  它。 (每张照片是5 KB之间 -
  20 kb的; )

2- When the web Page is requested and loaded, then I want all the photos are shown near the each text boxes 10 by 10 from top of the page till the end of it. (Each photo is between 5 kb - 20 kb; )

我知道ImageHandler的问题是
  我怎么才能把这些想法变成现实
  生活?一些例子和想法会
  太棒了!谢谢
  这个问题已经回答了,你可以看下 - > <一个href=\"http://stackoverflow.com/questions/2897466/downloading-photos-on-the-client-side-every-10-seconds-on-an-ajax-enabled-asp-net\">here

I know ImageHandler's the question is how can I put all these idea into real life? some examples and ideas will be great ! thanks This issue has been answered and you may have a look -> here

问候
BK

推荐答案

你是问,如果你的脚本会工作,或者你问这是否是将其添加到页面的好办法?

Are you asking if your script will work, or are you asking if this is a good way to add it to the page?

插入脚本的网页以这种方式肯定会工作,但最好的做法会说你首先做一个检查:

Inserting the script in to the page in that way will certainly work, but best practice would say you do a check first:

if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "SmartPenCheck"))
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "SmartPenCheck", strJS, false);

这样做它,虽然这样有点凌乱。无需重新编译应用程序,你不能代替脚本。你没有得到你会从一个单独的JavaScript文件有它的缓存。这是更难了很多调试。它是凌乱的cs文件阅读。

Doing it this way though is a little messy. You cannot replace the script without recompiling the app. You don't get the caching you would have from having it in a separate javascript file. It is a lot harder to debug. It is messy to read in the .cs file.

您要保存,当您需要插入动态值到JavaScript的(如控件ID)添加JavaScript的这个方法,或者您需要更改脚本是基于一些其他标准插入。

You want to save this method of adding javascript for when you need to insert dynamic values into the javascript (like control IDs), or you need to change which script is inserted based on some other criteria.

这篇关于Page.ClientScript注册一个对JavaScript的code的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆