20 Sep 2004

验证控件中显示的信息要换行竟然要用“" 啊

如果在javascript内
要用alert显示换行的信息则

<script language=javascript>
alert(
1 2 3)
</script>


今天我想RegularExpressionValidator的错误信息ValidationSummary被显示用MessageBox方式显示的时候
随手写下了ErrorMessage=“电话号码格式不正确!\r\n 正确的格式是8为数字”
<asp:RegularExpressionValidator id=“RegularExpressionValidator1” runat=“server” ErrorMessage=“电话号码格式不正确!  正确的格式是8为数字”
                                ValidationExpression
=“1{1}d{7}$” ControlToValidate=“box_danweiTelephone” Display=“Dynamic”></asp:RegularExpressionValidator>


“\r\n”竟然被原样显示了
改为
<asp:RegularExpressionValidator id=“RegularExpressionValidator1” runat=“server” ErrorMessage=“电话号码格式不正确!<br> 正确的格式是8为数字”
                                ValidationExpression
=“2{1}d{7}$” ControlToValidate=“box_danweiTelephone” Display=“Dynamic”>
</asp:RegularExpressionValidator>


居然可以了 真是有点想不通哦


  1. 1-9 [return]
  2. 1-9 [return]

18 Sep 2004

撞墙吧 Array.IndexOf(xxx)

要在后台把CheckBoxList的某个ListItem 的selected给true了
遍历该CheckBoxList,写下了下面注释内的代码,死活不能选中我的第个CheckBox

            string bigClassId = ( ( DataRowView)e.Item.DataItem )[模块编号].ToString();
            
string bigClassName =  ( ( DataRowView)e.Item.DataItem )[模块名称].ToString();
            CheckBoxList chk_list_big 
= (CheckBoxList)e.Item.FindControl(chk_list_bigas CheckBoxList;
            
if(chk_list_big != null)
            
{                    
                chk_list_big.Items.Clear();
                ListItem item 
= new ListItem();
                item.Text 
= bigClassName;
                item.Value 
= bigClassId;
                chk_list_big.Items.Add(item);
                chk_list_big.Attributes[
onclick= String.Format(CheckAll(‘{0}’),chk_list_big.ClientID);
                
//将符合用户模块的ListItem选定    
    
                
for(int i=0; i<this.taxiUser.Modules.Length; i++)
                
{
                    
if( bigClassId == this.taxiUser.Modules[i] )
                    
{
                        chk_list_big.Items.FindByValue(
this.taxiUser.Modules[i]).Selected = true;
                    }

                }

                

//真是见了鬼了!为什么用这样的方法不能选定该ListItem???

//                foreach(ListItem listItem in chk_list_big.Items)
//                {
//                    if(Array.IndexOf(this.taxiUser.Modules,listItem.Value) > 0)
//                    {
//                        listItem.Selected = true;
//                    }
//                }

半天不能醒悟就想着换道道,写了”该死”那行上面的几行代码把数组放倒来,(站着不行我就躺着来),发现可行,然后就开始发楞,命名原理一摸一样的啊,真是“见鬼”,对者这几行代码发了会愣,就决定还要狠狠的
if (Array.IndexOf(xxxxx) > 0) 用力
555555,撞的头都疼了.

18 Sep 2004

真郁闷,ListItem的Attributes让我碰到了

想给CheckBoxList的Item加个Onclick执行的javascript函数
 

CheckBoxList chk_list_big = (CheckBoxList)e.Item.FindControl("chk_list_big"as CheckBoxList;
            
if(chk_list_big != null)
            
{
                ListItem item 
= new ListItem(bigClassName,bigClassId);
                chk_list_big.Attributes[
"onclick"= String.Format("CheckAll({0})",bigClassId);
                item.Attributes.Add(
"onclick" , String.Format("CheckAll({0})" , bigClassId));
                chk_list_big.Items.Add(item);
            }


死活不行啊,

原来想这样的人好多啊
http://weblogs.asp.net/fmarguerie/archive/2003/02/27/3103.aspx
http://unboxedsolutions.com/sean/archive/2004/05/04/213.aspx

http://support.microsoft.com/default.aspx?scid=kb;en-us;309338&Product=NETFrame

后来只有加在CheckBoxList上了,虽然可以用但是发送到客户端的html内是把onclick加到input type =checkbox 外层的table上了

18 Sep 2004

真郁闷,ListItem的Attributes让我碰到了

想给CheckBoxList的Item加个Onclick执行的javascript函数
 

CheckBoxList chk_list_big = (CheckBoxList)e.Item.FindControl("chk_list_big"as CheckBoxList;
            
if(chk_list_big != null)
            
{
                ListItem item 
= new ListItem(bigClassName,bigClassId);
                chk_list_big.Attributes[
"onclick"= String.Format("CheckAll({0})",bigClassId);
                item.Attributes.Add(
"onclick" , String.Format("CheckAll({0})" , bigClassId));
                chk_list_big.Items.Add(item);
            }


死活不行啊,

原来想这样的人好多啊
http://weblogs.asp.net/fmarguerie/archive/2003/02/27/3103.aspx
http://unboxedsolutions.com/sean/archive/2004/05/04/213.aspx

http://support.microsoft.com/default.aspx?scid=kb;en-us;309338&Product=NETFrame

后来只有加在CheckBoxList上了,虽然可以用但是发送到客户端的html内是把onclick加到input type =checkbox 外层的table上了

15 Sep 2004

问题,如何把上传文件的浏览按钮换成其他样式 或者图片

我的上篇随笔中,写了如何替换“浏览”按钮的代码
有朋友指出 该表单无法提交,
由于我当时只是测试了 能否实现替换和浏览
我测试了一下,果然不能提交表单 提示“。。。权限。。”
后来修改如下

<%@ Page Language=C# ResponseEncoding=gb2312 debug=true%>
<%@ import Namespace=System %>
<%@ import Namespace=System.IO %>
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns=http://www.w3.org/1999/xhtml xml:lang=gb2312 lang=gb2312>
<head>
<title> 上传的时候<input type=file>中用图片代替浏览按钮 </title>
<meta http-equiv=Content-Type content=text/html; charset=gb2312 />
<meta name=title content=”” />
<meta name=author content=活靶子,huobazi />
<meta name=subject content=”” />
<meta name=language content=gb2312 />
<meta name=keywords content=”” />
<meta name=Copyright content=”” />
<meta name=robots content=all />
<script language=c# runat=server>
    
void Button_Click(object o , EventArgs e)
    
{        
            
string str = browse.PostedFile.ContentLength.ToString();
            Response.Write(str);
    }

    
void Page_Load(object o , EventArgs e)
    
{
        
    }

</script>
<script language=javascript type=text/javascript>
    function fn_browse()
    
{
        document.all.browse.click();
        document.all.file.value 
= document.all.browse.value;
        
        
    }

    function fn_submit()
    
{
        document.forms[
0].browse.disabled = true;        
    }

</script>

</head>
<body>

<form runat=server method=post enctype=multipart/form-data >

<input type=file  id=browse  runat=server style=display:none/>

<input type=text name=file />
<a href=# onclick=fn_browse()>
<img  name=btn src=browse.gif border=0 /></a>  
<br />
<br />
<input id=button type=submit value=提交 onServerClick=Button_Click runat=server 
onclick
=fn_submit />

</form>

</body>
</html>


该表单可以提交了,但是仍然不能上传所选文件,不知各位有没有其他办法?

15 Sep 2004

问题,如何把上传文件的浏览按钮换成其他样式 或者图片

我的上篇随笔中,写了如何替换“浏览”按钮的代码
有朋友指出 该表单无法提交,
由于我当时只是测试了 能否实现替换和浏览
我测试了一下,果然不能提交表单 提示“。。。权限。。”
后来修改如下

<%@ Page Language=C# ResponseEncoding=gb2312 debug=true%>
<%@ import Namespace=System %>
<%@ import Namespace=System.IO %>
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns=http://www.w3.org/1999/xhtml xml:lang=gb2312 lang=gb2312>
<head>
<title> 上传的时候<input type=file>中用图片代替浏览按钮 </title>
<meta http-equiv=Content-Type content=text/html; charset=gb2312 />
<meta name=title content=”” />
<meta name=author content=活靶子,huobazi />
<meta name=subject content=”” />
<meta name=language content=gb2312 />
<meta name=keywords content=”” />
<meta name=Copyright content=”” />
<meta name=robots content=all />
<script language=c# runat=server>
    
void Button_Click(object o , EventArgs e)
    
{        
            
string str = browse.PostedFile.ContentLength.ToString();
            Response.Write(str);
    }

    
void Page_Load(object o , EventArgs e)
    
{
        
    }

</script>
<script language=javascript type=text/javascript>
    function fn_browse()
    
{
        document.all.browse.click();
        document.all.file.value 
= document.all.browse.value;
        
        
    }

    function fn_submit()
    
{
        document.forms[
0].browse.disabled = true;        
    }

</script>

</head>
<body>

<form runat=server method=post enctype=multipart/form-data >

<input type=file  id=browse  runat=server style=display:none/>

<input type=text name=file />
<a href=# onclick=fn_browse()>
<img  name=btn src=browse.gif border=0 /></a>  
<br />
<br />
<input id=button type=submit value=提交 onServerClick=Button_Click runat=server 
onclick
=fn_submit />

</form>

</body>
</html>


该表单可以提交了,但是仍然不能上传所选文件,不知各位有没有其他办法?

14 Sep 2004

小技巧,如何把上传文件的浏览按钮换成其他样式 或者图片

 

本随笔缩写内容有误,对不起,谢谢!


csdn上有朋友问道这个问题
上google跑了跑,从这里和csdn的980337(面包喳喳) 朋友的回复得到提示,做了做测试。
以下代码可以把“浏览”按钮换成图片
当然 也可以不用<img>而改input或者button加上样式表(css)或者htc也应该可以吧。

<!DOCTYPE html PUBLIC ”-//W3C//DTD XHTML 1.0 Transitional//EN” ”http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=“http://www.w3.org/1999/xhtml" xml:lang=“gb2312” lang=“gb2312”>
<head>
<title> 上传的时候<input type=“file”>中用图片代替浏览按钮 </title>
<meta http-equiv=“Content-Type” content=“text/html; charset=gb2312” />
<meta name=“title” content=“” />
<meta name=“author” content=“活靶子,huobazi” />
<meta name=“subject” content=“” />
<meta name=“language” content=“gb2312” />
<meta name=“keywords” content=“” />
<meta name=“Copyright” content=“” />
<meta name=“robots” content=“all” />
<script language=“javascript” type=“text/javascript”>
    
function fn_browse()
    
{
        document.test_form.browse.click();
        document.test_form.file.value 
= document.all.test_form.browse.value;        
        
    }

</script>
</head>
<body>

<form name=“test_form” method=“post” ENCTYPE=“multipart/form-data” onsubmit=“alert(document.test_form.browse.value);” />
<input type=“file” name=“browse” style=“display:none;” />
<input type=“text” name=“file” />
<href=“javascript:fn_browse();”>
<img  name=“btn” src=“browse.gif” border=“0” />  
<br />
<br />
<input type=“submit” name=“提交表单” />
</form>

</body>
</html>

23 Aug 2004

MSDN中文站增加了几篇关于Smart Client的翻译文章

最近正在看智能客户端方面的资料,发现中文的甚少,
不料今日去MSDN中文站,发现本周更新里多出好多关于智能客户端的文章,正是前几日在看的英文文章的翻译
能看到中文资料,太高兴了,谢谢译者!

23 Aug 2004

MSDN中文站增加了几篇关于Smart Client的翻译文章

最近正在看智能客户端方面的资料,发现中文的甚少,
不料今日去MSDN中文站,发现本周更新里多出好多关于智能客户端的文章,正是前几日在看的英文文章的翻译
能看到中文资料,太高兴了,谢谢译者!

21 Aug 2004

疑惑 关于 多条件判断语句 的写法

写法1
if ( 条件1 && 条件2)
{
      //代码
}
写法2
if ( 条件1 )
{
       if( 条件2 )
      {
            //代码
      }
}
我一直认为写法1要比写法2条理清晰,容易阅读.
不知其他人如何认为呢?
今天在微软的KB中阅读 使用 Visual Basic .NET 在采用基于表单身份验证的 ASP.NET 应用程序中实现基于角色的安全性 的时候
发现这样的写法

public void Application_AuthenticateRequest( Object src , EventArgs e )
{
if (!(HttpContext.Current.User == null))
   
{
if (HttpContext.Current.User.Identity.AuthenticationType == "Forms" )
      
{
System.Web.Security.FormsIdentity id;
id 
= (System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity;
String[] myRoles 
= new String[2];
myRoles[
0= "Manager";
myRoles[
1= "Admin";
HttpContext.Current.User 
= new System.Security.Principal.GenericPrincipal(id,myRoles);
      }

   }

}



而且这则KB的VB版本也是这样的写的.
这样写有优越性?