Solved

JavaScript dynamically assigned properties don't maintain their state after postback

Posted on 2006-11-02
9
213 Views
Last Modified: 2009-12-16
I have a table with bunch of checkboxes. When i click on the checkbox, i use JavaScript to change the table's background color. When i press the update button, all background properties comes with their default values. Is there any way i can prevent these properties being reset to their default values?

Thanks,
0
Comment
Question by:Carl3003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 22

Expert Comment

by:WMIF
ID: 17862821
do you have these javascript's in functions?  you can create one function that calls each function to check all of these properties, and set them appropriately.  then you call this function in the body onload attribute.  if you would like help, please paste the javascript code you are using.
0
 

Author Comment

by:Carl3003
ID: 17862862
the javascript is simple. It change the table's cell backgroung color from red to blue or vice versa. Howevere, what happens after posting back is that the background color returns to its original value.
I have thought of many ways of how to go around this problem but what i am really looking for is a solution that doesnt involve extra coding.
If there is any way to associate my viewstate with table's cell properties so that everytime i postback, the viewstate will maintain the table's background color.
0
 

Author Comment

by:Carl3003
ID: 17862883
function ToggleList(ListId, link)
{
    var childList = document.getElementById(ListId);
    var refImg = link.children[0];
   
    if(childList==null)
        return;

    if(childList!=null && childList.style.display == "none")
    {
        refImg.src = "images/gif/minus.gif";
        childList.style.display = "block";
    }
    else
    {
        refImg.src = "images/gif/plus.gif";
        childList.style.display = "none";
    }        

}
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 22

Accepted Solution

by:
WMIF earned 25 total points
ID: 17862968
the only way that i know how to keep those colors would be to create a pageload function.

function pageload() {
  ToggleList(ListId1, link1);
  ToggleList(ListId2, link2);
  ToggleList(ListId3, link3);
  ToggleList(ListId4, link4);
  ToggleList(ListId5, link5);
}


then add it into your body tag:

<body onload="pageload()">
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 17865270
HI,

i hope you  did change the background color using javascript..

while changing the background color keep your change in a hidden field also!!

ie,

changing Red to Green then
update a hidden field with a value 1

and this value shld check in your body onload

<body onload="initLoad();">

function initLoad()
{
if (document.getelementByid("hiddenId").value == 1)
 {
 // set your color
}
else
{
// set another color
}

And in server code for not postback

set hiddenId.Value = 1 ; // default color

}

Regards
Renju
0
 
LVL 4

Expert Comment

by:satish_nagdev
ID: 17866543
hi carl,
well simply put when you update some values etc of control from javascript they are not persisted on postbacks.
however what you could do is have hidden fields with runat = server, in that set values of properties etc.
like documet.all.hiddenfieldid.value = "somevalue"
then in postback you can get values of properties etc that you want to set like
hiddenfieldid.value = Request["hiddenfieldid"]
control.property.value = hidenfieldid.value

hope it helps

regards,
satish
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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