asp2.0 textbox.Attributes.Add("onfocus", "this.value=function()")
this.textbox.Attributes.Add( "onfocus ", "this.value=function() ")
function为后台函数;
private string function()
{
return Other.getNum();
}
Other.getNum()为类库中定义的方法;
如何将取得textbox的焦点时。将function()返回的值傅给textbox???
------解决方案--------------------//这段是客户端脚本,除非是ajax,否则不能取到服务器方法的返回值得
this.value=function()
------解决方案--------------------用AJAXPRO
this.textbox.Attributes.Add( "onfocus ", "this.value=命名空间.类.function() ")
[Ajaxpro.AjaxMethod()]
private string function()
{
return Other.getNum();
}
------解决方案-------------------- <input onfocus= "this.value=x() ">
<script>
function x()
{
return 'ok '
}
</script>
------解决方案--------------------用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 ");
------解决方案--------------------顺便提点无关话题的
string str = i.ToString( "000# ");
格式化成4位的不够四位前面补0
------解决方案--------------------使用Ajax:
首先,在Page_Load中插入:Ajax.Utility.RegisterTypeForAjax(typeof(WebForm1.Other));
然后在Other类文件中得方法getNum()的上面插入语句:[Ajax.AjaxMethod]
这样就可以啦,记得要引入Ajax.dll文件哟~~
昨天刚刚学会的~~~~~