在jQuery返回的HTML中找到控件
16lz
2021-01-22
I have page Webform1.aspx and one GrvData.ascx user control. i am dynamically displaying usercontrol in webfom1.aspx page... i want to access grvitem in webform1.aspx.cs which is in GrvData.ascx. full design and code is bellow..
我有页面Webform1.aspx和一个GrvData.ascx用户控件。我在webfom1.aspx页面中动态显示usercontrol ...我想访问grvData.ascx中的webform1.aspx.cs中的grvitem。完整的设计和代码如下:
webform1.aspx
<form runat="server">
<input type="button" value="Load" runat="server" />
<input type="button" value="Submit" runat="server" />
<div id="result"></div>
</form>
<script>
$(document).ready(function () {
// on load button click jquery
$.ajax({
type: "POST",
url: "Webform1.aspx/Result",
data: "{ ClientIDD : '" + clientidd + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$('#result').html(response.d);
},
error: function (msg) {
alert(msg);
}
});
});
</script>
code behind
Webform1.aspx.cs
[WebMethod]
public static string Result(string ClientIDD)
{
return Results(ClientIDD);
}
public static string Results(string ClientIDD)
{
try
{
Page page = new Page();
System.Web.UI.UserControl userControl = (System.Web.UI.UserControl)page.LoadControl("GrvData.ascx");
Type t = userControl.GetType();
MethodInfo addtext = t.GetMethod("BindMyGrid");
addtext.Invoke(userControl, new object[] { ClientIDD });
// ControlHub.Controls.Add(userControl);
userControl.EnableViewState = true;
HtmlForm form = new HtmlForm();
form.Controls.Add(userControl);
page.Controls.Add(form);
StringWriter textWriter = new StringWriter();
HttpContext.Current.Server.Execute(page, textWriter,false);
return textWriter.ToString();
}
catch (Exception ex)
{
return ex.ToString();
}
}
GrvData.ascx
<asp:gridview id="grvitem" runat="server"
width="100%" autogeneratecolumns="False"
datakeynames="ID" EmptyDataText="No records found" >
<Columns>
<asp:TemplateField >
<ItemTemplate >
<input type="checkbox" id="chk" value="getIndex" onclick="chng(<%# Eval("Amount") %>,this);" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ServiceName" HeaderText="Description" />
<asp:BoundField HeaderText="Rate" DataField="Rate" />
<asp:BoundField HeaderText="QTY" DataField="QTY" />
<asp:TemplateField HeaderText="Price">
<ItemTemplate>
<asp:Label ID="lblListPrice" runat="server" Text='<%#Eval("Amount")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
Code Behind
public void BindMyGrid(string clientid)
{
// bind the data to the grid
grvitem.DataSource = data;
grvitem.DataBind();
}
Please tell me how to access grvitem in webform1.aspx.cs...
请告诉我如何在webform1.aspx.cs中访问grvitem ...
1 个解决方案
#1
0
If you return HTML content from server please remove the following from your jQuery ajax call
如果从服务器返回HTML内容,请从jQuery ajax调用中删除以下内容
contentType: "application/json; charset=utf-8",
dataType: "json",
Since it requests JSON as return type
因为它请求JSON作为返回类型
更多相关文章
- 加载函数加载页面但不能对数据执行任何操作
- 在Woocommerce结帐页面使用AJAX和Fee API进行动态折扣
- 从一个页面上的AJAX帖子获得NTLM挑战
- Web App可以在不刷新页面的情况下最好地添加,删除和编辑行
- jquery蔚蓝网总结三个页面
- Fullcalendar:为什么日历在页面上出现两次?
- jQuery使用微调器加载整个HTML页面
- 基于jQuery实现页面搜索功能----项目实战
- js jquery 关闭弹出页面 并刷新父页面(window.opener)