473,586 Members | 2,682 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Web User Controls

Hi All

I created web user control that has a few properties and an Update method.
These controls all get initialised and configured (all properties set) at
the page load event.

Today I included an if(!this.IsPost Back) {} around the initialisation code,
so that if an error occurred when the user was trying to update the
database, I could send them back with all their amended data in tact (not
the data back from database).

Now, when I try to update the page, my user controls still exist, but their
properties are no longer set!! Is there a way around this, I'm new to .Net
and may just be taking the wrong train of thought.

Any advice would be greatly appreciated.

Many Thanks

Luke

Nov 15 '05 #1
2 1370
Luke Ward wrote:
Hi All

I created web user control that has a few properties and an Update
method. These controls all get initialised and configured (all
properties set) at the page load event.

Today I included an if(!this.IsPost Back) {} around the initialisation
code, so that if an error occurred when the user was trying to update
the database, I could send them back with all their amended data in
tact (not the data back from database).

Now, when I try to update the page, my user controls still exist, but
their properties are no longer set!! Is there a way around this, I'm
new to .Net and may just be taking the wrong train of thought.

Any advice would be greatly appreciated.


My question to you is what mechanism are you using to repopulate the data
back into the controls after an update, either successful or failure. I
would guess that on a successful update you would want to initialise the
page as you do on first load so that any data that might have been modified
by triggers or other actions on the database would be retrieved. If that's
the case, you're initialise code needs to be enhanced slightly so that in
the else of your if(!IsPostBack) you still reload the control data from the
database if the update were successful.

Also in the else, you need to decide how you want to reload the controls
with the user input data if the update failed. You can use one of the built
in mechanisms such as viewstate or you can write your own.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
Nov 15 '05 #2
Thanks Tom

You guess right, on success I can reload the page as first load, on failure
I want to preserve the page and user entered data. So I suppose I just need
to reset all the properties of my user controls on failure or success, I
just thought they would stay set for some reason.

Thanks

Luke

"Tom Porterfield" <tp******@mvps. org> wrote in message
news:ec******** ******@TK2MSFTN GP12.phx.gbl...
Luke Ward wrote:
Hi All

I created web user control that has a few properties and an Update
method. These controls all get initialised and configured (all
properties set) at the page load event.

Today I included an if(!this.IsPost Back) {} around the initialisation
code, so that if an error occurred when the user was trying to update
the database, I could send them back with all their amended data in
tact (not the data back from database).

Now, when I try to update the page, my user controls still exist, but
their properties are no longer set!! Is there a way around this, I'm
new to .Net and may just be taking the wrong train of thought.

Any advice would be greatly appreciated.
My question to you is what mechanism are you using to repopulate the data
back into the controls after an update, either successful or failure. I
would guess that on a successful update you would want to initialise the
page as you do on first load so that any data that might have been

modified by triggers or other actions on the database would be retrieved. If that's the case, you're initialise code needs to be enhanced slightly so that in
the else of your if(!IsPostBack) you still reload the control data from the database if the update were successful.

Also in the else, you need to decide how you want to reload the controls
with the user input data if the update failed. You can use one of the built in mechanisms such as viewstate or you can write your own.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.

Nov 15 '05 #3

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

Similar topics

1
2123
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...
6
3359
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all the usual stuff of recreating the usercontrol in the Page Init event. The 'failure' sequence is as follows: - select web form button to display...
3
2225
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for some reason I keep getting the error: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
8
3168
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem I'm having is that the partial class signature in my projectDetails.ascx.cs file looks like this: public partial class...
3
2787
by: Terry Olsen | last post by:
I'm trying to add a domain user to a local group using the code below: Dim LCL As New DirectoryEntry("WinNT://" + Environment.MachineName + ",computer") Dim DOM As New DirectoryEntry("WinNT://us.ups.com") Dim DOMUSR As DirectoryEntry = DOM.Children.Find("USERID", "user") Dim LCLGRP As DirectoryEntry = LCL.Children.Find("LOCAL_GROUP",...
0
7839
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...
0
8338
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...
1
7959
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...
0
8216
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...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
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...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
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.