本文介绍了从pagemethods调用的静态方法访问aspx控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用PageMethods从静态方法中访问控件并设置aspx页面中存在的控件的属性。



例如:

How can i access the controls and set the properties of the controls, that are present in the aspx page, inside the static method which is called from javascript using PageMethods.

for eg:

<html>
<head>
<script type="text/javascrip">
   var timer;
   function chk_me()
   {

       clearTimeout(timer);
       timer = setTimeout(function validate()
       {
           var name = document.getElementById(<%=txtname.ClientID>).value;
           var address = document.getElementById(<%=txtaddress.ClientID>).value;
           PageMethods.ProcessIT(name, address, onSucess, onError);
           function onSucess(result) {
               alert(result);
           }
           function onError(result) {
               alert("Something wrong.");
           }
       }, 2000);
   }
</script>
</head>

<body>
<form id="form1"  runat="server">
<asp:ScriptManager ID='ScriptManager1' runat='server' EnablePageMethods='true' />
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
<asp:TextBox ID="txtaddress" runat="server"></asp:TextBox>
 <asp:TextBox ID="txt_1" runat="server" onkeyup="chk_me()"></asp:TextBox>
</form>
</body>
</html>





代码背后





In Code Behind

[WebMethod]
   public static void ProcessIT(string name, string address)
   {

   Here I want to access the textbox
and set the textbox properties dynamically.How can i achieve that.

   }

推荐答案


这篇关于从pagemethods调用的静态方法访问aspx控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 01:48