473,785 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databind to an custom object at runtime

Hello

How do I databind a ASP.NET Texbox to a custom object.

I a WinForm I do it like this:

Dim myCustomerObjec t As Customer()
Private Sub CreateNewCustom er
myCustomerObjec t = New Customer()
myCustomerObjec t.FirstName = "Thomas"
firstnameTextbo x.DataBindings. Add("Text", myCustomerObjec t, "FirstName" )
'firstnameTextb ox is a Texbox on My Form
End Sub

When I change the firstnameTextbo x.Text property via the User Interface my
object is updated atomically.

How do I do this in ASP.NET? Is this possible? If not possible at runtime...
can I do it at design time using the Eval function?

Thomas

Nov 18 '05 #1
1 1898
Hi Thomas,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you'd like to bind a custom object to a ASP.NET
TextBox so as to make them synthronic just like the binding for the winform
TextBox in winform applicaiton.
If there is anything I misunderstood, please feel free to let me know.

As for this question, here is my suggestion on it:
In dotnet, the develop mode and design patterns are quite different between
the winform application and the ASP.NET web applcation.

In winform application, since all the class's instance and resource are all
in memory on a single machine during the runtime. It's ok to bind a control
with a object instance in memory and when the control's value changed, also
synthornize the control with the object instance.

However, in ASP.NET web application(in fact, not only ASP.NET,also for any
other web application). The model is quite different from the winform
application. The enviroment of a web application is distributed, include
the serverside and the clientside. Our ASP.NET applicaiton is running on
the serverside and when a customer request a certain page from his
clientside. The ASP.NET application compiled and executed the page and
output the response html to the client. Then, the connection between client
and the server will be stoped. The customer view the page on the
clientside. So only during the time when the page is executing on the
serverside, there're page's object instances and other custom component
instance in the server memory. We can specify control's data field value at
that time. But after the page is output and sent to client, all the page's
instances in server memory will be cleared.( It's just a page's life cycle
on serverside).
For more detailed info on ASP.NET web page's life cycle and processing, you
may view the follwing article on MSDN:
#Web Forms Page Processing
http://msdn.microsoft.com/library/en...mspageprocessi
ngstages.asp?fr ame=true

Since the different mechanism of web based application, we're not able to
implement the same databind mode as what in winform application in ASP.NET
web application. Also, the ASP.NET web controls has the different internal
mechanism and performance from the winform control. Then on the serverside,
it is constructed as a control objected instance in memory, then, it is
rendered out as html element into response page to the client. In ASP.NET
we use the VIEWSTATE to store the web control's states. But the key point
is when in client side, they are just some html elements doesn't have
memory instance like they are on the serverside. So generally, we set the
controls value and property on serverside before it is sent to clientside.
Also, we retrieve its value when the page is posted back again from client
to the serverside.
For more information on the ASP.NET server control, you may view the below
reference in MSDN:

#Introduction to ASP.NET Server Controls
http://msdn.microsoft.com/library/en...uctiontowebfor
mscontrols.asp? frame=true

also, here is some web links on web application design patterns which maybe
helpful:
#Web Presentation Patterns
http://msdn.microsoft.com/library/en...presentationpa
tterns.asp?fram e=true

Please check out my above suggestions. If you have any questions on it ,
please feel free to let me know.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2

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

Similar topics

5
2191
by: rufus | last post by:
Hi, I have a custom collection class that inherits from HashTable. When I add a new CustomObject to my CustomCollection I would like to ensure that it will only accept objects of type CustomObject. How would I do this? Thanks in advance. Public Class CustomCollection Inherits Hashtable ' default constructor
7
4755
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException and is defined in an assembly common to the client and server components. The custom class merely defines three (3) constructors -- the null constructor; one with a string parameter; and one with a string and innner exception parameter -- that...
2
3950
by: Kel Good | last post by:
Hello, I am binding a custom IList object to a DataList that I am using for a web menu. The items in the custom IList have properties that allow me to dynamically define how my menu behaves. My binding syntax is standard: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MenuItems.DataSource = GetMyCustomIList MenuItems.DataBind()
1
1512
by: Martin | last post by:
Hi, I've got a web label control which I set a databind expression on the Text attribute in the html for the page (aspx file). At runtime, I want to override this attribute, so before I do MyLabel.databind() (or actually Page.DataBind()), I set Text to "". This doesn't work because then the databind comes along and redefines the Text attribute.
0
1157
by: Bryce Budd | last post by:
Hi, I have a webform which has several server controls attached. The entire form is data bound to custom objects. The collection objects are cached using the Cache object. In my use case, I have to update my database, synchronize my cached collection and refresh my UI. After my database update I call dropdownlist1.databind() and my items are exactly the same when they should be less 1 item. If I understand the "control execution...
3
2643
by: Zachary Turner | last post by:
Hello, I have a situation where I would like to perform custom serialization and deserialization of an existing .NET framework object (specifically, System.DateTime). Is there a common paradigm here, for how I can override the default behavior of DateTime serialization and provide my own? I want to use this custom serialized DateTime in many places, and don't want to provide custom serialization routines for every single object that...
3
2029
by: Mark Leistner | last post by:
I am having problems getting a gridview to bind to custom objects under any non-full trust level. I created a test project to verify what I am seeing isn't a side effect of other code in my project and I get the same errors there: Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.
4
5834
by: ThunderMusic | last post by:
Hi, I have a custom form that works fine when I debug it or run it in release mode but cannot be loaded in the designer... Actually, it can be loaded in the designer when no control is on it, but the resizing tool (in the designer) is offset both horizontally and vertically and when I put a control on it, as soon as I save, the designer throws an exception (but cannot be reproduced everytime) and the form cannot be loaded anymore unless...
11
18151
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with ListView columns so it should be doable, thanks
0
9645
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
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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
10091
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
9950
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
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
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.