Click here to Skip to main content
16,018,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I'm using asp.net.
I want to update a part of my page (not whole page) without sending the page request to the server. I want to do this in the client side.
for this, I think I should use AJAX and javascript.

I've created a handler page: handler.ashx
I send a request and get response in plain text:
(in javascript)
...
XMLHttpRequest.open("GET", url);
XMLHttpRequest.onreadystate = ApplyUpdate; // ApplyUpdate is a function that get the response in client side(javascript).
XMLHttpRequest.send(null);
...

(in handler.ashx)
...
response.write("plain text as response");
...

Now in ApplyUpdate function I can use the plain text and show it in client browser.

BUT
the problem is this:
I have a placeholder1 control in asp.net: <asp:PlaceHolder ID="PlaceHolder1" runat="server">

How can I assign the plain text (the response !) to a label control and add the label to placeholder1 control !?
I mean how I can use these codes in client side:
Label lb1 = new Lable();
lb1.text = plaintext;
placeholder1.controls.add(lb1);

these codes are in c# (code-behind) but how I can use such these codes?
I cannot do the same thing by javascript codes !

excuse my bad explanation.
I'll appreciate any help.
Posted

1 solution

You are facing in the right direction. But you don't have to reinvent the wheel.
On one hand you have the webmethod scenario for any general case. See: http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/calling-an-Asp-Net-C-Sharp-method-web-method-using-javascript/[^], on the other hand you have the UpdatePanel[^] and many other Ajax controls in the toolkit[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900