473,385 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

javascript controls disappear

10
im creating controls using javascript, but whenever there is a postback on the page all the controls created in javascript disappear.
How do i fix this problem.
the code below shows how im creating them.

Expand|Select|Wrap|Line Numbers
  1. var txt5   = document.createElement("input");
  2.               txt5.setAttribute ('type', 'text');
  3.               txt5.setAttribute ('id', j[0]);
  4.               txt5.setAttribute ('name', j[0]);
  5.               txt5.setAttribute ('text', j[0]);
  6.               var chk1 = document.createElement("input");
  7.               chk1.setAttribute ('type', 'checkbox');
  8.               chk1.setAttribute ('id', "chk" + j[0] );
  9.               chk1.setAttribute ('name',"chk" +  j[0]);
  10.               chk1.setAttribute ('text',"chk" +  j[0]); 
  11.               //chk1.innerHTML  = "Default";
  12.               var lbl1   = document.createElement('label');
  13.               lbl1.setAttribute ('id', "lblDefault" );
  14.               lbl1.innerHTML =  "Default";
  15.               lbl1.style.width = "30px";
  16.               var lbl3   = document.createElement('label');
  17.               lbl3.setAttribute ('id', "lbl" + j[0]);
  18.               lbl3.innerHTML =  j[0];
  19.               lbl3.style.width = "125px";              
  20.               txt5.style.top='15px';
  21.               txt5.style.left='15px';
  22.               var newdiv = document.createElement('div');
  23.               di.setAttribute('id',"divIdName");                            
  24.               di.appendChild(lbl3);
  25.               di.appendChild(txt5);
Mar 18 '09 #1
8 2512
acoder
16,027 Expert Mod 8TB
You need to recreate them using the same code on page load.
Mar 18 '09 #2
omlac
10
i added this line on init but it just runs trough the line and doesnt call the java function when its a postback, it only run once(the first time)

ClientScript.RegisterStartupScript(Me.GetType(), "ctrScript", "<script language = 'javascript'>LoadControls('" & strParams & "')</script>")

Thanks
Mar 18 '09 #3
acoder
16,027 Expert Mod 8TB
I'm not sure about ASP.NET, but in JavaScript you can use window.onload or event listeners, e.g.
Expand|Select|Wrap|Line Numbers
  1. if (window.addEventListener)
  2.     window.addEventListener("load", LoadControls, false);
  3. else if (window.attachEvent)
  4.     window.attachEvent("onload", LoadControls);
  5. else 
  6.     window.onload= LoadControls;
Mar 18 '09 #4
omlac
10
thanks,
my function loadcontrols has a parameter strParams which is generated in code behind(either onload or on init). do u thinki will be able to pass this parameter if i useevent listners.

Thanks
Mar 18 '09 #5
acoder
16,027 Expert Mod 8TB
Use a function() object:
Expand|Select|Wrap|Line Numbers
  1. if (window.addEventListener)
  2.     window.addEventListener("load", function() { LoadControls(params); }, false);
  3. else if (window.attachEvent)
  4.     window.attachEvent("onload", function() { LoadControls(params); });
  5. else 
  6.     window.onload= function() { LoadControls(params); };
Mar 18 '09 #6
omlac
10
thanks, it worked, that fixed it
Mar 19 '09 #7
acoder
16,027 Expert Mod 8TB
That's cool. Thanks for posting.
Mar 19 '09 #8
Frinavale
9,735 Expert Mod 8TB
I have no idea why you are doing what you are doing....

I just wanted to mention that if you plan on using Ajax in your asp web application you should register your scripts with the ScriptManager instead of the Page.ClientScript....

I'm not even sure your code would work in an Ajax solution...so don't mind me.
Mar 24 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Spartanicus | last post by:
I'm pondering what the various drawbacks are of the methods to code UI elements who's function relies on javascript and css. Currently on http://www.pan-europe.utvinternet.ie/ I use styled <a>...
2
by: Rachel Suddeth | last post by:
Here is my scenario: I have a few custom controls that I set up on a form and tested setting properties and appearances. Then I added a couple references to the project which add classes I need to...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
3
by: Fred Flintstone | last post by:
I'm a bit confused about something. I have an aspx page populated with dynamic controls; textboxes, labels, radios and so on. On the page is a Yes/No radio combination and 3 textboxes. The...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
0
by: HP | last post by:
Hi there I have a datalist control with some bound controls in its Item Template and a gridview bound to one of those fields (residing also in Item Template). I've found out that when I click...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
0
by: e_spork | last post by:
I am using Page.ClientScript.RegisterStartupScript to throw up a Javascript alert box. When I click OK on the alert box, all the controls on my page disappear and I don't understand why. I can...
4
by: =?Utf-8?B?UmljaGFyZA==?= | last post by:
Hi, I have an ASP .NET page with codebehind in a vb file. The page has a dropdown control, and a JS function which used HTTP XML Request to get the data from the database, and populate the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.