Jquery 在Ajax动态创建的用户控件中传递参数重复值
关于使用Ajax通过web表单发送的用户控件和参数,我遇到了一个问题。 我使用的用户控件只包含一个标签Jquery 在Ajax动态创建的用户控件中传递参数重复值,jquery,asp.net,dynamic-usercontrols,Jquery,Asp.net,Dynamic Usercontrols,关于使用Ajax通过web表单发送的用户控件和参数,我遇到了一个问题。 我使用的用户控件只包含一个标签 <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Message.ascx.cs" Inherits="Message" %> <asp:Label ID="lblMessage" runat="server" Text="lblMessage"></asp:Label> 并将参数从web
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Message.ascx.cs" Inherits="Message" %>
<asp:Label ID="lblMessage" runat="server" Text="lblMessage"></asp:Label>
并将参数从web表单传递给用户控件,如下所示:
<script type = "text/javascript">
$(document).ready(function(){
$("#demo").click(function () {
$.ajax({
type: "POST",
url: "CS.aspx/LoadUserControl",
data: "{message: '" + $("#message").val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
$("#Content").append(r.d);
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<input type = "text" id = "message" />
<input type = "button" id = "demo" value = "Load" />
<div id = "Content">
</div>
</form>
</body>
</html>
$(文档).ready(函数(){
$(“#演示”)。单击(函数(){
$.ajax({
类型:“POST”,
url:“CS.aspx/LoadUserControl”,
数据:“{message:'”+$(“#message”).val()+“}”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(r){
$(“#内容”)。追加(研发);
}
});
});
});
问题是,当我多次单击按钮时,“内容”中的值会重复几次,而不是只重复一次,并用我分配给文本框的新值重新填充。
有人知道为什么吗?
我希望,每次单击按钮时,用户控件都会收到值,并只填充一次信息,而不是几次。replace
$("#Content").append(r.d);
宽度
$("#Content").append(r.d);
$("#Content").html(r.d);