edit inner html div
i am a beginner
function PopupUserRegist() { result = $.ajax({ url: "Default.aspx?cmd=Setting", async: false , complete: function () { // unblock when remote call returns } }).responseText; ; }
protected void Page_Load(object sender, EventArgs e) { if (Request["cmd"] == "Setting") { div.InnerText = "test"; //This does not change inner text } }
protected void Button2_Click(object sender, EventArgs e) { div.InnerText = "test";//This change inner text }
when call Po开发者_运维知识库pupUserRegist(); does not change?
You've got confused about the flow of control with ASP.NET.
Page_Load()
occurs on the server side at page generation time and can change the data that is about to be sent back in the HTML page to the browser.
When you call the ASPX again through ajax()
from JavaScript, the codebehind can't directly touch the page content, because that's already sitting over on the browser. If you want to change the data in the page, you'll have to have the ASPX return a plain value to the JavaScript code in the responseText
:
$('#myDiv').text(
$.ajax({
url: 'Default.aspx?cmd=Setting',
async: false
}).responseText
);
or, better, avoiding the unpleasant use of synchronous xmlhttprequest:
$.get('Default.aspx?cmd=Setting', function(result) {
$('#myDiv').text(result);
});
If you really want to blur the line between code that runs on the client and server sides, look at using runat="server"
, click events, postbacks and viewstates.
Check if the condition is met.
精彩评论