Cómo actualizar el contenido Div sin generar todo el contenido de un archivo html

I have an HTML file inside <body /> tag with structure:

<div id='header'>content of header</div>

<div id='content'>content of content.</div>

<div id='footer'>content of footer</div>

El contenido de header, content y footer are changed as per user interaction.

User selects content for header section, The header section adds the user content to the header <div />.

For this I made three stringbuilder variables respective to the three <div />s in c#, whenever there is a change in any <div /> the respective string builder variable updates and I am making an HTML temp file with <head /> sección y una <body /> section—and finally appending all the string builders to the <body /> tag and saving the file. And if user wants to download the file, the file should have all the updates.

How to update the particular <div /> content from code behind with c# with out making temp file?

I need changes directly on the file and I don't want to redesign the temp page in code behind.

preguntado el 10 de marzo de 12 a las 01:03

3 Respuestas

using update panel can resolve your issue.

just update the div in your codebehind.


respondido 10 mar '12, 01:03

Iam already using UpdatePanels, Whenever there is a change,the respective stringbuilder will update using updatepanels.Current i am making a temp file with string builder like stringbuilder.appenLine('html+ head+ scripts+css +/head body'+header Stringbuilder+contentstringbuilder+footerStringbuilder+'/body+/html'). this content is storing in to temp file and again replacing the actual file with temp file.this is what i am doing. but i need the changes in stringbuilder. directly go and update the actual file rather than creating a temp file with all syntax and replace the file with actual file. - 1509

why not store the updates in just the stringbuilder and then build the file upon download request? - hijo

You can use the following code for changing the content of specific Div. Try the following code in your code behind file

For Header header.InnerText = "Changed content of header";

same for other divs.

respondido 10 mar '12, 06:03

You could indeed use updatepanel like mentioned above or even better, make an asynchrone call in javascript to your server and update the element of choice with the response.

You could use jQuery (see: jQuery.com) for the async call (e.g. with $.getJSON or $.ajax) and modify the contents of the div with jQuery to like: $("#header").html(yourResult).

The call to the server could be handled by a handler (.ashx) or WCF service or whatever works for you.

Hope this gets you further!


Respondido 12 Abr '12, 14:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.