this.textbox.Attributes.Add("onfocus", "this.value=function()")
function为后台函数;private string function()
{
    return Other.getNum();
}Other.getNum()为类库中定义的方法;如何将取得textbox的焦点时。将function()返回的值傅给textbox???

解决方案 »

  1.   

    //这段是客户端脚本,除非是ajax,否则不能取到服务器方法的返回值得
    this.value=function()
      

  2.   

    我知道要用ajax但是不知道怎么实现
      

  3.   

    用AJAXPROthis.textbox.Attributes.Add("onfocus", "this.value=命名空间.类.function()")[Ajaxpro.AjaxMethod()]
    private string function()
    {
        return Other.getNum();
    }
      

  4.   

    <input onfocus="this.value=x()">
    <script>
    function x()
    {
     return 'ok'
    }
    </script>
      

  5.   

    public partial class PersonManage_PersonData_PersonalData : System.Web.UI.MobileControls.MobileUserControl

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {            this.Txt_PeopelID.Attributes.Add("onfocus", "this.value=getPeopleID()");
            }
        }[AjaxPro.AjaxMethod]
        private string getPeopleID()
        {
             return Other.getNum("WK","personaldata","gonghao","gonghao");
        }}
      

  6.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    //using Ajax;
    /// <summary>
    /// Other 的摘要说明
    /// </summary>
    ///public class Other
    {
        
    public Other()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }    public static string getNum(string bh, string tablename, string DataColumn, string orderby)
        {
            
            DataTable DT = Base.ReturnData("Select Top 1 " + DataColumn + " from " + tablename + "  where  leaveflag=0 and " + DataColumn + " like '" + bh + "____'order by " + orderby + " desc");
            if (DT.Rows.Count == 0) { return bh + "0001"; }
            string ID = DT.Rows[0][0].ToString();
            ID = ID.Substring(bh.Length);
            int i = int.Parse(ID);
            i = i + 1;
            string str = i.ToString();
            switch (str.Length)
            {
                case 1:
                    return bh + "000" + i;
                case 2:
                    return bh + "00" + i;            case 3:
                    return bh + "0" + i;
                default:
                    return bh + "0001"; ;
            }    }
    }
      

  7.   

    用ajaxpro
    1。工程添加对ajaxpro的引用
    2.修改web config,增加
    <location path="ajaxpro">
        <system.web>
          <httpHandlers>
            <add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro"/>
          </httpHandlers>
          <!--
    If you need to have Ajax.NET Professional methods running on the
    login page you may have to enable your own authorization configuration
    here.
    -->
          <!--
    <authorization>
    <deny users="?"/>
    </authorization>
    -->
        </system.web>
      </location>
    3.在page load里面写
    AjaxPro.Utility.RegisterTypeForAjax(typeof(PersonManage_PersonData_PersonalData));
            this.TextBox1.Attributes.Add("onfocus", "this.value = PersonManage_PersonData_PersonalData.getPeopleID().value");
      

  8.   

    Microsoft JScript 运行时错误: 'Sys.Res.enumValueNotInteger' 为空或不是对象
      

  9.   

    <input onfocus="this.value=x()">
    <script>
    function x()
    {
     return function();}
    </script>如何调用后台的function();
      

  10.   

    顺便提点无关话题的
    string str = i.ToString("000#");
    格式化成4位的不够四位前面补0
      

  11.   

    上面不是告诉你怎么用了吗
    下一个ajaxpro
    Microsoft JScript 运行时错误: 'Sys.Res.enumValueNotInteger' 为空或不是对象
    ===》
    这你应该用的是asp.net ajax
      

  12.   

    使用Ajax:
    首先,在Page_Load中插入:Ajax.Utility.RegisterTypeForAjax(typeof(WebForm1.Other));
    然后在Other类文件中得方法getNum()的上面插入语句:[Ajax.AjaxMethod]
    这样就可以啦,记得要引入Ajax.dll文件哟~~
    昨天刚刚学会的~~~~~