使用ajax在aspx中绑定Usercontrol

时间:2015-07-18 07:36:16

标签: c# asp.net ajax

在下面的代码中我有一个usercontrol Control.ascx我有一个文本框和下拉列表,我想用db检查字段是文本框还是下拉列表,我想使用ajax在sample.aspx中显示。请帮我这样做。

Control.ascx

<table width="100%">
<tr>
      <td>
         <input type="text"  id="btnField" value="Val" />
      </td>
      <td>
         <select id="cbB" style="width:75%"></select>
      </td>
</tr>
</table>    

sample.aspx

  <table>
       <tr>
           <td>
               <uc1:UcReport ID="ucReport" runat="server" />
           </td>
       </tr>        
    </table>        

     function LoadUserControl() {

            $.ajax({
                type: "POST",
                url: "Sample.aspx/LoadControls",
                data: "",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (r) {

                    var data = $.parseJSON(r.d);
                    alert(r.d);  
                }
            });        
        }

         //will return textbox or dropdown
         [System.Web.Services.WebMethod]
         public static string LoadControls()
         {
              string Test= "2";

              Client Controls = new Client();
              DataSet dsField = Controls.GetFieldData(Int32.Parse(Test));
              string sReturn = JsonConvert.SerializeObject(dsField.Tables[0]).ToString();
              return sReturn;     
         }

0 个答案:

没有答案