JS中调用后台方法进行验证
前台:
【   
<script language="javascript" type="text/javascript">
        function checkcommun() {
            PageMethods.CheckCommunCode(document.getElementById("txtCommunCode").value, OnComplete);  //PageMethods.调用的后台函数名(参数,...(可以有多个参数),回调函数(必须放在最后一位))
          
           
        }
        function OnComplete(result) { //function 回调函数名(result)
            if (result!=true) {
                alert('XXXX');
                document.getElementById("txtCommunCode").value = '';
                document.getElementById("txtCommunCode").focus();
            }
        }

    </script>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">   //EnablePageMethods="true":在JS中可以调用后台的函数
</asp:ScriptManager>
<asp:TextBox ID="txtBuildCode" runat="server" onblur="checkBuildCode()"></asp:TextBox>//onblur="checkBuildCode()":失去焦点时对输入的内容进行验证

后台:

 [System.Web.Services.WebMethod]  //异步调用的函数
        public static bool CheckCommunCode(string communcode)   //必须用public static标明,回调函数必须返回bool
        {
            BLL.WC_Community_Info bll = new BeidouWY.BLL.WC_Community_Info();
            DataSet ds = bll.GetList("CommunityCode='" + communcode.Trim() + "'");
            if (ds.Tables[0].Rows.Count != 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

?可以为null 

public static Int32? StrToInt(string sqlText)  //Int32?表示返回值可以是Int32类型的也可以是NULL
        {
            try
            {
                return Convert.ToInt32(sqlText);
            }
            catch
            {
                return null;
            }
        }
  
private int? _buildlaycnt;  //此参数是int类型或者为NULL
public int? BuildLayCnt   //此属性表示赋值和取值可以是int类型也可以赋予NULL值
  {
   set{ _buildlaycnt=value;}
   get{return _buildlaycnt;}
  }

在GridView中指定一列为超级链接并有查询字符串的写法
<asp:HyperLinkField DataNavigateUrlFields="ID"
                    DataNavigateUrlFormatString="CommunDetial.aspx?ID={0}" Text="详细" />
//上述的DataNavigateUrlFields指定的是后面URL中的参数为绑定的DataSet中的ID列
或者:
<a href='FloorDetail.aspx?ID=<%#Eval("ID") %>'>详细</a>

posted on 2010-06-01 11:33  秦威龙  阅读(2289)  评论(0编辑  收藏  举报