say i write a small webpage and use a content div for certain items, is it possible i can change that div using a different html file? or should i just write out all the changes in the code somewhere?
Possible to change div contentbetween html files
Page 1 of 1
10 Replies - 3567 Views - Last Post: 09 August 2010 - 07:16 AM
Replies To: Possible to change div content
#3 Guest_Guest*
Re: Possible to change div content
Posted 06 August 2010 - 08:55 AM
no what i want to do is load an html page into a div based on what link a user clicks. so say you have 1, 2, and 3. if the user clicks 1 i want the div to show content for page 1, if they click 2 then page 2, etc. but the content would be in separate html files.
#4
Re: Possible to change div content
Posted 06 August 2010 - 08:59 AM
I think you're thinking about HTML frames.
#5 Guest_Guest*
Re: Possible to change div content
Posted 06 August 2010 - 09:01 AM
i want to avoid frames and iframes if possible.
#6
Re: Possible to change div content
Posted 06 August 2010 - 09:02 AM
Then you would have to use something like Javascript to dynamically change the HTML.
#7 Guest_Guest*
Re: Possible to change div content
Posted 06 August 2010 - 09:09 AM
asp.net cannot do this?
#8
Re: Possible to change div content
Posted 06 August 2010 - 10:38 AM
yes, you can dynamically create controls on the fly, but it's a pain-in-the-ass to deal with.
If you don't have to dynamically create controls, don't. If you can create them at design time and just hide the until you need to show them, that's a better solution than dynamically creating them.
Normally, if I have multiple "frames" of content, I will create multiple DIVs and simply show/hide the DIVs from the code-behind. It's hard to tell if you could do this since you gave so little information.
If you don't have to dynamically create controls, don't. If you can create them at design time and just hide the until you need to show them, that's a better solution than dynamically creating them.
Normally, if I have multiple "frames" of content, I will create multiple DIVs and simply show/hide the DIVs from the code-behind. It's hard to tell if you could do this since you gave so little information.
#9
Re: Possible to change div content
Posted 06 August 2010 - 11:10 AM
Here is a link for a tutorial about the ASP .NET Multiview and View controls. By the sounds of it, I think that this is basically what you're looking for. The MultiView control works in tandem with an embedded View control. Each View control acts as a content container, and behaves very much like a Panel or Canvas area. At run time, the MultiView control manages the View controls to ensure only one View is visible at a time.
Hope this helps
Hope this helps
#10
Re: Possible to change div content
Posted 06 August 2010 - 11:13 AM
You could easily load the content of these other HTML pages into the DIV if these HTML pages are partial pages. Meaning they don't contain the HTML, TITLE, or BODY tags.
If these only contain the HTML that you would find inside the BODY tag, then simply load the content into the INNERHTML property of the DIV.
You can do this by giving the DIV an ID and then adding the runat="server" attribute. You will then have access to the DIV from the code-behind. Then it is simply a matter of inserting the HTML into the INNERHTML propery of the DIV.
It would be extremely helpful if you posted an example of what you are trying to insert into the DIV.
If these only contain the HTML that you would find inside the BODY tag, then simply load the content into the INNERHTML property of the DIV.
You can do this by giving the DIV an ID and then adding the runat="server" attribute. You will then have access to the DIV from the code-behind. Then it is simply a matter of inserting the HTML into the INNERHTML propery of the DIV.
It would be extremely helpful if you posted an example of what you are trying to insert into the DIV.
#11
Re: Possible to change div content
Posted 09 August 2010 - 07:16 AM
Eclipsed4utoo and Jayman has been giving some pretty solid advice in this thread.
Dealing with dynamic controls is a pain it the ...
It is a lot easier to place the content into ASP.NET Panels (these render as <div> elements) and use the Panel.Visible property to indicate whether or not to render them. If you set Panel1.Visible=False then this panel, and all of the controls within it will not be rendered (the HTML will not be generated for the controls).
When the user clicks a button/hyperlink/linkbutton/tab: whatever control that is supposed to cause the content to change...you just set the Visibile property of the panels to display the one that the user wants to view.
It will be smoother for the user if you use Ajax (UpdatePanels) so that the page loading/unloading ("flicker") isn't apparent.
Another solution you could consider is using Javascript.
Place the controls for the "pages" into Panels (like I suggested) but set all of the Panels' Visible properties to True. Use CSS to hide the Panels that are not selected (display:none) and when the user clicks the control to display the next "page" use Javascript to set the CSS styles for all the panels to display:none except for the one selected...set this one to display:block. This solution will eliminate the need to postback to the server to get the "next page". Just be aware that all of the HTML content, for all of the controls, is sent to the browser the first time the page is loaded.
-Frinny
Dealing with dynamic controls is a pain it the ...
It is a lot easier to place the content into ASP.NET Panels (these render as <div> elements) and use the Panel.Visible property to indicate whether or not to render them. If you set Panel1.Visible=False then this panel, and all of the controls within it will not be rendered (the HTML will not be generated for the controls).
When the user clicks a button/hyperlink/linkbutton/tab: whatever control that is supposed to cause the content to change...you just set the Visibile property of the panels to display the one that the user wants to view.
It will be smoother for the user if you use Ajax (UpdatePanels) so that the page loading/unloading ("flicker") isn't apparent.
Another solution you could consider is using Javascript.
Place the controls for the "pages" into Panels (like I suggested) but set all of the Panels' Visible properties to True. Use CSS to hide the Panels that are not selected (display:none) and when the user clicks the control to display the next "page" use Javascript to set the CSS styles for all the panels to display:none except for the one selected...set this one to display:block. This solution will eliminate the need to postback to the server to get the "next page". Just be aware that all of the HTML content, for all of the controls, is sent to the browser the first time the page is loaded.
-Frinny
This post has been edited by Frinavale: 09 August 2010 - 07:16 AM
Page 1 of 1
|
|

New Topic/Question
Reply
MultiQuote












|