0
votes

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 PopupUserRegist(); does not change?

2

2 Answers

1
votes

Check if the condition is met.

2
votes

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.