I am loading a dynamic html files (a.html,b.html....) in my aspx page using jquery load page. But i have controls in that html file and i dont know how to set values for that html comtrols from the (code behind of) aspx page..
Ex : jus a outline
1. Preview.aspx
<body>
<div id="htmlPlaceholder">
// gonna place the below html file here.
</div>
</body>
2. a.html
<body>
<span id="lblNname" runat="server"></span>
</body>
3. In preview.aspx.cs
i want to set value for lblNname
I hope it makes sense. can anybody help?
Thanks in advance.
I don't believe it is possible using WebForms.
I would do the following to get around your problem:
$(function() {
...
$.ajax('a.html', function(data) {
$("#htmlPlaceHolder").html(data);
$.ajax('/path/to/datasource/GetText', function(text) {
$("#lblNname").text(text);
});
});
...
});
Of course you would write some error handling in there to make sure that the data you are getting is what you are expecting before writing it to the page.
设置标签文字的示例
lblNname.InnerHtml = Server.HtmlEncode("Welcome! You accessed this page at: " + DateTime.Now);
Thanks for replying So is it something like this,
$('#htmlPlaceHolder').load('a.html',function(){
$.ajax('preview.aspx/GetData', function(text) {
$("#lblNname").text(text);
});
});
Thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.