PC Review


Reply
Thread Tools Rate Thread

Adding elements on client side

 
 
simonZ
Guest
Posts: n/a
 
      26th Sep 2007
I have <div id="divTbl" runat="server" enableviewstate="true"> control on my
asp.net page.

Than I add some html elements into this div element with javascript on
client side:
<script language="javascript">

var divAdd=document.createElement("div");
divAdd.id="divTest";
divAdd.innerText="test";

var divTbl=document.getElementById("<%=divTbl.ClientID%>");
divTbl.appendChild(divAdd);

</script>

On client it works, I can see new elements in my div element.
But when I post back my page, the divTbl.InnerHtml is empty.
Why and how can I do this?

Regards,
Simon


 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      26th Sep 2007
"simonZ" <(E-Mail Removed)> wrote in message
news:O4K9$(E-Mail Removed)...

> On client it works, I can see new elements in my div element.


Yes, you would...

> But when I post back my page, the divTbl.InnerHtml is empty.


That's right.

> Why


In order for a control to be part of the postback, it has to be sent down to
the client in the first place. Controls which are created client-side are,
therefore, not part of this so you can't see them when the page is posted
back...

> and how can I do this?


If you're only interested in the dynamically created <div>'s innerHTML
property, copy it into a hidden field before you kick off the postback...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      26th Sep 2007
the browser only posts back name value pairs for the form elements of
the form doing the submit (browsers support more than 1 form per page
even though asp.net only supports 1). form elements are <input>,
<select> and <textarea>. they must be enabled and have a name attribute
to be posted back. (in the case of input type=checkbox or tye=radio they
must also be checked).

if you dynamically add a <input> with client code it will be posted
back, but asp.net has no code to add it to the server side page model.
you will have to write this code.

-- bruce (sqlwork.com)


simonZ wrote:
> I have <div id="divTbl" runat="server" enableviewstate="true"> control on my
> asp.net page.
>
> Than I add some html elements into this div element with javascript on
> client side:
> <script language="javascript">
>
> var divAdd=document.createElement("div");
> divAdd.id="divTest";
> divAdd.innerText="test";
>
> var divTbl=document.getElementById("<%=divTbl.ClientID%>");
> divTbl.appendChild(divAdd);
>
> </script>
>
> On client it works, I can see new elements in my div element.
> But when I post back my page, the divTbl.InnerHtml is empty.
> Why and how can I do this?
>
> Regards,
> Simon
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding / removing <asp:ListBox elements client-side Mark Rae Microsoft ASP .NET 2 23rd Sep 2006 06:38 PM
Adding Server Side code in a Client Side Script??? =?Utf-8?B?TWlrZSBSYW5k?= Microsoft ASP .NET 1 30th Jan 2006 08:52 PM
Collectiong Data on Server side while adding rows on client side =?Utf-8?B?U2lsZWVzaA==?= Microsoft ASP .NET 0 3rd Nov 2004 12:43 AM
Problem in adding template of server side control using client side scripts Lau Lei Cheong Microsoft ASP .NET 1 13th Oct 2004 11:41 AM
Adding custom client-side onClick handler with client-side validator controls Zoe Hart Microsoft ASP .NET 1 8th Jan 2004 10:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:58 AM.