Hello all,
I'm trying to change the innerHtml of a div in the code behind and noticed an interesting thing. If I have this situation:
aspx file:

<div id="displayPanel" runat="server">



displayPanel.InnerHtml += "<span>"+ name + " has donated £ " + donation + "</span>";

everything goes as planned (the div is populated with how many rows are in the SQL table and the data is wrapped in a span as I wanted). But if the displayPanel div has a .net control in it as in

<div id="displayPanel" runat="server">
    <asp:Label ID="label1" runat="server" Text="label" />

with the same code behind, I get an error saying "Cannot get inner content of divID because the contents are not literal". Why is that? I'm not trying to get the innerHtml of the controller - which understandably could lead to a compiling error, but I'm trying to get the innerHtml of the div!

Well like the error states, the div contains a control, not literal text. InnerHTML is expecting literal content.

I haven't tried your approach... I recommend you use a repeater control for displaying from a DB query. Or a gridview.

However I like the repeater because you can include basic HTML elements too and it's fast and easy.

Thanks JorgeM, I have used that approach because I didn't know any other I suppose. Never heard of a repeater control or grid view...sorry I'm still at the very beginning

That's understandable...

I recommended that you look at some books in another thread...

What I did years ago when I was interested in asp.net was... I first bought the book ... "learn asp.net in 21 days" by Sams teach yourself. it was very good because i did one lesson a day and i got a good start on quickly creating a website. But then i really wanted to learn C# so i bought a beginner's book from Apress. Then just started reading MSDN documentation and working on projects and helping others.

i am by no means an expert, but i can say that I've learned quite a bit since then.

that's partially what I did and what I'm doing. I looked for a book for a little while, found what looked good to me, as a real beginner, ASP.NET 3.5 A beginners Guide by William B. Sanders and I began to learn, by copying the exercises first and by doing small apps (I'm still working on the Overtime one by the way, https://www.daniweb.com/web-development/aspnet/threads/484634/overtime-application from scratch because I read a few things that convinced me that I was doing it the wrong way and it looks like I am getting it to work), so will see where we get :-). As for master pages, repeaters, grids etc, as I said before I knew nothing about those because they were not mentioned in the book - no book is perfect - but no doubt it will be good to look into that :-)

You'll find that asp.net is huge... i'm still learning every day. Just keep working on examples, tutorials..etc.. try to run through examples that allow you to use all of the web controls available to you. There are quite a bit (in your toolbox in VS) that help you do things easier. However, you'll find many occassions where you need more control over your code and you'll want to develop the code on your own rather than using a web or html control. asp.net takes time and practice.


you'll want to develop the code on your own rather than using a web or html control.

You mean you can develop your own controls?

thanks I will have a look at this!

I also suggest you start researching or using jQuery for creating cool html pages - it fun and easy to learn, visit www.jquery.com