473,789 Members | 2,876 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Initialize an user control after it's loaded

Hi,
Is there a way to initialize an user control after it's loaded? I know this
is a strange question, so allow me to elaborate, I have an user control
which allow users to enter customer data and save them into SQL server. The
user control has about 50 textboxes and other web controls. To simplify,
let's say user control contains a textbox txtCompany and another textbox
called txtContact, for the first company, I entered "ABC plumbing" into
txtCompany , "Joe Smith" into txtContact. Then I tried to enter second
company, "ABC plumbing" and "Joe Smith" remain in the textboxes, I know
this is the way it is. Question is, is there a way to initialize the user
control after the first company is saved?

I know I can use codes to set txtCompany and txtContact to "", that's not
what I want. Cause I have over 100 user controls of this kind and each of
them has an average of 30-70 web controls, it's a lot of works to write an
initialize routine for every control.

TIA
Nov 18 '05 #1
3 1923
How about setting ViewState property to "False"

Regards,
Jignesh Desai.

"Danny Ni" <dn**@yahoo.com > wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,
Is there a way to initialize an user control after it's loaded? I know this is a strange question, so allow me to elaborate, I have an user control
which allow users to enter customer data and save them into SQL server. The user control has about 50 textboxes and other web controls. To simplify,
let's say user control contains a textbox txtCompany and another textbox
called txtContact, for the first company, I entered "ABC plumbing" into
txtCompany , "Joe Smith" into txtContact. Then I tried to enter second
company, "ABC plumbing" and "Joe Smith" remain in the textboxes, I know
this is the way it is. Question is, is there a way to initialize the user
control after the first company is saved?

I know I can use codes to set txtCompany and txtContact to "", that's not
what I want. Cause I have over 100 user controls of this kind and each of
them has an average of 30-70 web controls, it's a lot of works to write an initialize routine for every control.

TIA

Nov 18 '05 #2
You can loop through the Controls property of the user control and
give all the child controls a default value.
See: http://odetocode.com/Articles/71.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 29 Nov 2004 23:15:09 -0800, "Danny Ni" <dn**@yahoo.com > wrote:
Hi,
Is there a way to initialize an user control after it's loaded? I know this
is a strange question, so allow me to elaborate, I have an user control
which allow users to enter customer data and save them into SQL server. The
user control has about 50 textboxes and other web controls. To simplify,
let's say user control contains a textbox txtCompany and another textbox
called txtContact, for the first company, I entered "ABC plumbing" into
txtCompany , "Joe Smith" into txtContact. Then I tried to enter second
company, "ABC plumbing" and "Joe Smith" remain in the textboxes, I know
this is the way it is. Question is, is there a way to initialize the user
control after the first company is saved?

I know I can use codes to set txtCompany and txtContact to "", that's not
what I want. Cause I have over 100 user controls of this kind and each of
them has an average of 30-70 web controls, it's a lot of works to write an
initialize routine for every control.

TIA


Nov 18 '05 #3
This is more of a workaround, I guess. In my applications when I allow
users to save information, but remain on the page, I will usually send a
Response.Redire ct( Request.RawUrl ). This will cause the whole page to
refresh and "reinitiali ze" all the field values.

It might not work for what you want. You might display a "saved
successfully" method and allowing them to enter a new one. When this
happens, I will save the message to Session and on page_load, check for the
Session variable, display the message, and remove it from Session.

HTH,

bill

"Danny Ni" <dn**@yahoo.com > wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,
Is there a way to initialize an user control after it's loaded? I know this is a strange question, so allow me to elaborate, I have an user control
which allow users to enter customer data and save them into SQL server. The user control has about 50 textboxes and other web controls. To simplify,
let's say user control contains a textbox txtCompany and another textbox
called txtContact, for the first company, I entered "ABC plumbing" into
txtCompany , "Joe Smith" into txtContact. Then I tried to enter second
company, "ABC plumbing" and "Joe Smith" remain in the textboxes, I know
this is the way it is. Question is, is there a way to initialize the user
control after the first company is saved?

I know I can use codes to set txtCompany and txtContact to "", that's not
what I want. Cause I have over 100 user controls of this kind and each of
them has an average of 30-70 web controls, it's a lot of works to write an initialize routine for every control.

TIA

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1284
by: Josema | last post by:
Hi, Im starting to do the navigation of a portal, and for it, im using usercontrols.... Actually i have a user control in the top of the page that has some menus (contact, register, etc...) Depending of the menu that the user will clik i make a LoadControl to the specific user control. i start to see some problems following this way...
7
3262
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically load one of several controls: private void btnCategory_Click(object sender, System.EventArgs e) { Control myControl = LoadControl(DropDownList1.SelectedItem.Text + ".ascx"); PlaceHolder1.Controls.Add(myControl);
1
8167
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler, the user controls events fail to fire on the first click NOTE: I (believe I) am rebuilding all...
1
13722
by: Josh | last post by:
Hi Guys, I have been having a big problem with trying to pass parameters into a user control when the user control is dynamically loaded into a placholder. I am developing in c#. I have get and set methods on the user control "editButton.ascx" which work fine. How do i pass parameter into the user controls "c1", "c2" ? Here is a bit of my code that is calling the user control from the
3
1957
by: Guadala Harry | last post by:
I have this scenario: ASPX Page dynamically loads userControl1 - which in turn dynamically loads userControl2. UserControl2 contains a TextBox Web Server control. When a user clicks a button in the ASPX page (not in either user control), a Postback occurs during which I'd like to retrieve the Text property value of the TextBox control. I have plenty of examples to work from that show how to retrieve a property value of a user control...
1
2137
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new to programming, but I am new to ASP.NET and Web application design in general... loved the concept of user controls and dynamically adding them to a page. So what I wound up with was an application that dynamically loads two user controls directly...
3
1873
by: Matej Kavčič | last post by:
Hello, i have one problem. I use loadcontrol in default.aspx page. On page i have placeholder and on load i with loadcontral load dynamic some user control. Some times i must load same user control twice, like test.ascx, ockey thats no problem. But now in test.ascx is loaded twice so how can i now determinete in load function in user control whic one is. I also want to create that when i load user contol in default.aspx write some...
2
2091
by: Diffident | last post by:
Hello All, I have a nested user control i.e., Control B which is loaded from Control A. Control A is itself dynamically loaded from a web form. Control A has a "Save" button which loads the Control B dynamically. Now in Control B there is a "Return" button which calls the method A of Control A. In method A, a session variable is being retrieved. My problem is whenever the control is passed back to the Control A, error is being thrown...
5
3079
by: Andrew Robinson | last post by:
I have a page that can load a number of different user controls. Each of these user controls inherits from a common base class and the controls are loaded based on application state, status, etc and the specific type of control frequently changes. I have a common event in the base class that each child user control inherits from and that the page wires up and uses to get status from the child user control. I hope all pretty simple and not...
0
9665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.