Programatically change <div id="someid"> tag in ASP.NET.  when runat="server" not available

Posted on 2010-03-31
Medium Priority
Last Modified: 2012-05-09
I'm working with a tab control that's generated from a javascript library. I'm able to assign ids to the various tab panels for example <div id="panel1">, <div id="panel2">.  I'm trying to programmatically assign varying content to the various tab panels using vb.net.  However, because the panels are dynamically created by the javascript when the page loads, i'm not able to assign the runat='server' attribute in the div tag.  How to i reference these <div> id's in my code?
Question by:todd_nakasato
LVL 23

Expert Comment

by:Saqib Khan
ID: 29260022
how are you setting up runat attribute in javascript?

var d = document.createElement("div")
d.setAttribute("runat", "server")

did you consider adding server div controls using vb/c# instead?

Author Comment

ID: 29261345
the javascript is generated directly from a extjs panel control.  
LVL 28

Accepted Solution

sybe earned 750 total points
ID: 29320118
Well, of course if something is created on the client, your server-side code can not touch it.

But you have some options:
1. Pass (server-side generated) values of parameters along to the javascript library.
2. Get the desired content of divs through an AJAX call.
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

LVL 28

Expert Comment

ID: 29320572
Just wondering how you imagine a div that is created on the client to be running on the server?

ASP.Net is even worse than other web languages in that fools developers into thinking that there is no difference between client-side script and server-side script. So maybe you are forgiven.

But you should really understand that once the HTML has been sent to the browser, the server has no longer any control about what happens. From that moment it is the browser that takes control about what happens.
You might have included some javascripts in the HTML, but there is no guarantee that the browser will execute that javascript.

Assisted Solution

Stormjack earned 750 total points
ID: 29409009
Use the AJAX tab container from the Microsoft library.  You can interact with its properties in the code behind, set the contents of its panels, change the tab text, etc.

I use this heavily in several applications and it works like a champ.

Author Closing Comment

ID: 31709642

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question