Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-02
9
Medium Priority
?
220 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 22

Accepted Solution

by:
WMIF earned 100 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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 .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

610 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