Asp.net 组件开发中web资源文件(图片、js)的调用问题

Asp.net 自定义控件开发相关的几种嵌入资源解决方案

前提: 如下将要介绍的几种类型资源都要在其属性页窗口, 将 <生成操作> 属性, 设置为[嵌入的资源],

如图:

► 给自定义控件添加自定义图标的几种方案

   方法一:
          直接在自定义控件项目中添加一个 *.bmp格式的图标文件, 并将其命名
         与主控件文件相同, 扩展名为 .bmp, 比如主控件文件名为:
         CustomButton.cs, 则图标文件命名为: CustomButton.bmp . 编译项目.
         然后在工具箱中添加此控件就可以看到刚刚设置的图标效果.

   方法二:
           图标文件名称与主控件名称不同时, 在类前如下设置.

[ToolboxBitmap(typeof(CustomButton), @"CustomButton1.bmp")]
public class CustomButton : CompositeControl, INamingContainer
{
       //….;
}

编译项目,然后在工具箱中添加此控件就可以看到刚刚设置的图标效果.


   方法三:
            图标文件名称与主控件名称不同时, 用本机绝对路径. 如下:

           [ToolboxBitmap(@"E:/net/CustomButton(测试资源
           文件)/CustomButton/CustomButton1.bmp")]
         
           编译项目,然后在工具箱中添加此控件就可以看到刚刚设置的图标效果.

     
► 自定义控件嵌入JavaScript 文件资源

           1. 定义元数据属性
            [assembly: WebResource("CustomButton.CustomButton_JScript.js",
              "application/javascript")]
           namespace CustomButton
           {
                //….;
           }

           其中 WebResource 的参数1为: 控件命名空间 + . + JS脚本文件名称

      2. 使用

if (!Page.ClientScript.IsClientScriptIncludeRegistered
("MyJavaScript"))
        {
                Page.ClientScript.RegisterClientScriptInclude
               ("MyJavaScript",Page.ClientScript.GetWebResourceUrl
               (this.GetType(), " CustomButton. CustomButton _JScript.js"));
        }


► 自定义控件嵌入图片(gif/jpg 等) 文件资源

        1. 定义元数据属性
          
           [assembly: WebResource("CustomButton.NoPic.gif", "image/gif")]  
           namespace CustomButton
           {
                  //….;
           }

        2. 使用

          string strImageSrc = Page.ClientScript.GetWebResourceUrl
                (this.GetType(), "CustomButton.NoPic.gif");
          System.Web.UI.WebControls.Image img = new
               System.Web.UI.WebControls.Image();
          img.ImageUrl = strImageSrc;

0
0
(请您对文章做出评价)
« 上一篇: @import css OR link css
» 下一篇: Nettiers2.3 笔记
<script type="text/javascript"> try { GS_googleAddAdSenseService("ca-pub-4210569241504288"); GS_googleEnableAllServices(); } catch (e) { } </script> <script type="text/javascript"> try { GA_googleAddSlot("ca-pub-4210569241504288", "cnblogs_blogpost_body"); GA_googleAddSlot("ca-pub-4210569241504288", "cnblogs_commentbox_up"); GA_googleAddSlot("ca-pub-4210569241504288", "cnblogs_blogpost_bottom"); GA_googleAddSlot("ca-pub-4210569241504288", "cnblogs_blogpost_bottom1"); } catch (e) { } </script> <script type="text/javascript"> try { GA_googleFetchAds(); } catch (e) { } </script> <script type="text/javascript"> var blog_ad_has_shown = false; </script>
posted @ 2009-06-26 18:20 YaSin 阅读(140) 评论(0)   编辑 收藏 网摘

<script type="text/javascript"> var commentAuthorHasChecked = false; var commentAuthorIsValid = false; var commentUrlIsValid = true; var commentEmailIsValid = true; var authenCodeHasChecked = false; var authenCodeIsValid = true; var hasLogined = false; function PostComment() { var isValid = true; if($("#wrapAuthenCode").css("display")=="none"){ ShowAuthenCode(); $("#tip_AuthenCode").css("color","red"); $("#tip_AuthenCode").html("请输入验证码!"); isValid = false; } if(!hasLogined && !commentAuthorHasChecked){ CheckAuthor(); } if(!hasLogined && !commentAuthorIsValid){ isValid = false; } if(!authenCodeHasChecked){ CheckAuthenCode(); } if(!authenCodeIsValid){ isValid = false; } if(!hasLogined && !commentUrlIsValid){ isValid = false; } if(!commentEmailIsValid){ isValid = false; } if(!CheckCommentContent()){ isValid = false; } if(!isValid){ return; } var content = $("#tbCommentBody").val(); if(content.length>2000){ alert("评论内容过长!不允许发布!"); return; } if(content.indexOf(" E         E          E      ")>=0){ alert("该内容不允许布!"); return; } if ($("#span_comment_posted").html()!='' && $("#span_comment_posted").html()==content){ alert("该评论已发表过!"); return; } $("#tip_comment").html("评论提交中..."); $("#span_comment_posted").html(content); //content = content.replace("'", "//'"); var email = $("#tbCommentEmail").val(); var authenNum = $("#tbAuthenCode").val(); var authenId = $("#span_comment_test").html(); var comment = {}; comment.authenNum = authenNum; comment.authenId= authenId; comment.parentId = 0; comment.blogId = 53642; comment.sourceUrl = ''; comment.author = $("#tbCommentAuthor").val(); comment.url = $("#tbCommentAuthorUrl").val(); comment.authenCode = $("#tbAuthenCode").val(); comment.email = email; comment.title = ''; comment.content = content; comment.parentCommentId = $("#span_parentcomment_id").html(); $.ajax({ url: '/ws/CommentService.asmx/AddAnonymousComment', data: $.toJSON(comment), type: "post", dataType: "json", contentType: "application/json; charset=utf8", success: function(data) { if (data.d["IsSuccess"]) { ShowCommentMsg("感谢您的回复:)"); //RereshComments2(comment.parentId); $("#tbCommentBody").val(''); //$("#divCommentShow").html(data.d["ReturnData"]+content.replace(//n/g,"<br/>")+"<br/><br/>"); $("#divCommentShow").html($("#divCommentShow").html()+data.d["ReturnData"]); $("#tip_AuthenCode").html(''); RefreshAuthenCode(); $("#tbAuthenCode").val(""); CommentNotify(data.d["CommentID"]); } else { ShowCommentMsg(data.d["ReturnData"]);//"抱歉!评论提交失败!请与管理员联系。"); $("#span_comment_posted").html(''); } }, error: function(xhr) { ShowCommentMsg("抱歉!评论提交失败!请与管理员联系。"); $("#span_comment_posted").html(''); //alert(xhr.responseText); } } ); } function RefreshAuthenCode(){ AjaxPost("/ws/CommentService.asmx/RefreshAuthenCode","{}",RefreshImg); $("#lnkRereshAuthenCode").html("<span style='color:red'>刷新中...</span>"); return false; } function RefreshImg(response){ $("#imgAuthenCode").attr("src","/Modules/CaptchaImage/ValidCodeImage.aspx?id="+encodeURIComponent(response)); $("#span_comment_test").html(response); $("#lnkRereshAuthenCode").html("看不清,换一个"); } function ShowAuthenCode(){ //if($("#wrapAuthenCode").css("display")=="none"){ // AjaxPost("/ws/CommentService.asmx/RefreshAuthenCode","{}",ShowAuthenCodeOk); //} $("#wrapAuthenCode").show(); } function ShowAuthenCodeOk(response){ UpdateAuthenCode(); $("#tbAuthenCode").val(""); $("#wrapAuthenCode").show(); $("#tip_AuthenCode").html(''); } function CheckAuthor(isOnblur){ commentAuthorHasChecked = true; var maxLength = 30; if($("#tbCommentAuthor").val().length == 0){ $("#tip_author").html("请输入您的昵称!"); commentAuthorIsValid = false; return false; } else if($("#tbCommentAuthor").val().length > maxLength){ $("#tip_author").html("昵称不允许超过" + maxLength + "个字符!"); commentAuthorIsValid = false; return false; } else{ //if(isOnblur){ AjaxPost("/ws/CommentService.asmx/IsAuthorExist","{author:'"+$("#tbCommentAuthor").val()+"'}" ,OnCheckAuthorExist); //} //else{ // $("#tip_author").html(""); // commentAuthorIsValid = true; //} return true; } } function OnCheckAuthorExist(response){ if(!response){ $("#tip_author").html(""); commentAuthorIsValid = true; } else{ $("#tip_author").html("该昵称已被使用,请更换昵称"); commentAuthorIsValid = false; } } function CheckUrl(){ var maxLength = 50; var url = $("#tbCommentAuthorUrl").val(); if(url.length == 0){ commentUrlIsValid = true; return true; } else if(url.length > maxLength){ $("#tip_url").html("主页地址不允许超过" + maxLength + "个字符!"); commentUrlIsValid = false; return false; } else if(url.indexOf("http://")!=0 || url.indexOf(".") < 0){ $("#tip_url").html("主页地址要以“http://”开头"); commentUrlIsValid = false; return false; } else{ $("#tip_url").html(""); commentUrlIsValid = true; return true; } } function CheckEmail(){ var email = $("#tbCommentEmail").val(); if(email.length>0){ var regExp = new RegExp("//w+@((//w|/-)+//.)+[a-z]{2,3}"); if(!regExp.test(email)){ $("#tip_email").html("请输入正确的邮件地址!"); commentEmailIsValid = false; } else{ commentEmailIsValid = true; $("#tip_email").html(""); } } else{ commentEmailIsValid = true; $("#tip_email").html(""); } } function CheckAuthenCode(){ authenCodeHasChecked = true; var num = $("#tbAuthenCode").val(); var id = $("#span_comment_test").html(); $("#tip_AuthenCode").css("color","red"); if(num.length==0){ authenCodeIsValid = false; $("#tip_AuthenCode").html("请输入验证码!"); return; } else if(num.length!=4){ authenCodeIsValid = false; $("#tip_AuthenCode").html("请输入四位数字!"); return; } else if(new RegExp("(/d+)").test(num)){ authenCodeIsValid = false; $("#tip_AuthenCode").html("请输入四位数字!"); return; } else{ AjaxPost("/ws/CommentService.asmx/CheckAuthenCode","{number:"+num+",id:'"+id+"'}", OnCheckAuthenCode); } } function OnCheckAuthenCode(response){ if(response){ $("#tip_AuthenCode").css("color","green"); $("#tip_AuthenCode").html("验证码输入正确!"); authenCodeIsValid = true; } else{ $("#tip_AuthenCode").css("color","red"); $("#tip_AuthenCode").html("验证码输错啦!"); RefreshAuthenCode(); authenCodeIsValid = false; } } function CheckCommentContent(){ if($("#tbCommentBody").val().length==0){ alert("请输入评论内容!"); return false; } return true; } </script>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值