473,769 Members | 6,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wanted: Help making minimal example of delegation work in ASP/C#

I'm practicing for the C# brain bench test by reviewing how delegates work.
(Delegates are easy to to with visual studio because you normally use the
delegates that some API as already defined. I'm worried they are going to
make me do my own delegates from scratch.) I see that line 33 of
Default.aspx is indeed executing when I single step with the debugger. As
you can see (on lines of 17 and 18 of propertyDemo.cs I have set up a
delegate and I'm single stepping thu this too). But why do not the contents
'"old=abc" new="xyz"'show up in the list box I have set up? It is clearly
being added when I single step with the debugger.

I have set up session state and when that did not work I set up ViewState
and that did not help either!

File Default.aspx:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<script runat="server">
PropertyDemo pd;
/*005*/ protected void Clear_Click(obj ect sender, EventArgs e) {
/*006*/ tbValue.Text = "";
/*007*/ }
/*008*/ protected void PropertyDemo_Cl ick(object sender, EventArgs e){
/*009*/ pd.name = tbValue.Text;
/*010*/ }
/*011*/ protected void Page_Init(objec t sender, EventArgs e){
/*012*/ pd = new PropertyDemo();
/*013*/ pd.m_eventNameC hange += new
PropertyDemo.Na meChangeEvent(p d_m_eventNameCh ange);
/*014*/ lbLog.Items.Add ("init");
/*015*/ }
/*016*/ protected void Page_Load(objec t sender, EventArgs e){
/*017*/ lbLog.Items.Add ("load");
/*018*/ pd = (PropertyDemo)S ession["pd"];
/*019*/ if (pd == null){
/*020*/ pd = new PropertyDemo();
/*021*/ pd.m_eventNameC hange += new
PropertyDemo.Na meChangeEvent(p d_m_eventNameCh ange);
/*022*/ }
/*023*/ ArrayList litems = (ArrayList)Sess ion["log"];
/*024*/ if (litems != null)
/*025*/ foreach (object o in litems)
/*026*/ lbLog.Items.Add (""+o);
/*027*/ litems = (ArrayList)View State["log"];
/*028*/ if (litems != null)
/*029*/ foreach (object o in litems)
/*030*/ lbLog.Items.Add (""+o);
/*031*/ }
/*032*/ void pd_m_eventNameC hange(string sOld, string sNew){
/*033*/ lbLog.Items.Add ("old=" + sOld + " new=" + sNew);
/*034*/ SaveState();
/*035*/ }
/*036*/ protected void Page_Unload(obj ect sender, EventArgs e){
/*037*/ SaveState();
/*038*/ }
/*039*/ private void SaveState(){
/*040*/ lbLog.Items.Add ("page unload");
/*041*/ Session["pd"] = pd;
/*042*/ ArrayList log = new ArrayList();
/*043*/ foreach (object o in lbLog.Items){
/*044*/ log.Add(o);
/*045*/ }
/*046*/ Session["log"] = log;
/*047*/ ArrayList log2 = (ArrayList)Sess ion["log"];
/*048*/ ViewState["log"] = log;
/*049*/ }
/*050*/ protected void Set_Click(objec t sender, EventArgs e){
/*051*/ pd.name = tbValue.Text;
/*052*/ }
/*053*/ protected void getter_Click(ob ject sender, EventArgs e){
/*054*/ tbValue.Text = pd.name;
/*055*/ }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Demonstr ate Getters and Setters and Delegates</title>
</head>
<body>
<form id="form1" runat="server">
<table border="1" style="width: 40px; height: 38px">
<tbody>
<tr>
<td><asp:Butt on ID="setter" runat="server" Text="set"
OnClick="Set_Cl ick" /></td>
<td>
<asp:Button ID="getter" runat="server" Text="get"
OnClick="getter _Click" /></td>
<td><asp:Butt on ID="clearer" runat="server" Text="Clear"
OnClick="Clear_ Click" /></td>
<td>
<asp:TextBox ID="tbValue" runat="server"> </asp:TextBox></td>
</tr>
<tr><td colspan="4"><as p:ListBox ID="lbLog" runat="server"
Width="278px" Height="736px"> </asp:ListBox></td></tr>
</tbody>
</table>
</form>
</body>
</html>
File PropertyDemo.cs
/*001*/ using System;
/*002*/ using System.Data;
/*003*/ using System.Configur ation;
/*004*/ using System.Web;
/*005*/ using System.Web.Secu rity;
/*006*/ using System.Web.UI;
/*007*/ using System.Web.UI.W ebControls;
/*008*/ using System.Web.UI.W ebControls.WebP arts;
/*009*/ using System.Web.UI.H tmlControls;
/*010*/
/*011*/ /// <summary>
/*012*/ /// Summary description for PropertyDemo
/*013*/ /// </summary>
/*014*/ public class PropertyDemo
/*015*/ {
/*016*/ private string m_sName;
/*017*/ public delegate void NameChangeEvent (String sOld, String sNew);
/*018*/ public PropertyDemo()
/*019*/ {
/*020*/ }
/*021*/ public string name
/*022*/ {
/*023*/ get {
/*024*/ this.m_eventNam eChange(m_sName ,"");
/*025*/ return m_sName;
/*026*/ }
/*027*/ set {
/*028*/ this.m_eventNam eChange(m_sName , value);
/*029*/ m_sName = value;
/*030*/ }
/*031*/ }
/*032*/ }
/*033*/
Nov 25 '06 #1
0 1093

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

Similar topics

7
3276
by: Rene Pijlman | last post by:
Section 6.5 "What is delegation?" of the FAQ says: "Python programmers can easily implement delegation. For example, the following class implements a class that behaves like a file but converts all written data to uppercase: class UpperOut: def __init__(self, outfile): self.__outfile = outfile def write(self, s):
3
9172
by: Jane Doe | last post by:
Hello, I need to browse a list of hyperlinks, each followed by an author, and remove the links only for certain authors. 1. I searched the archives on Google, but didn't find how to tell the RegExp object to be non-greedy as using the ? quantifier doesn't seem to work. --------- SAMPLE ----------------
8
1623
by: Victor B. Berdin | last post by:
Hi everyone, I'm trying to make PostgreSQL 7.4 to work on a minimal Linux (2.4.22/libc-2.3.1) environment comprised of selected libraries and the latest busybox. So far, the binaries: "initdb", "pg_ctl" and "initlocation" (initlocation: not really required) won't work, and terminates with the "SIGSEGV" message. All other pg binaries/executables do not report the said segfault message.
0
1284
by: Daniel P. | last post by:
http://danutp.blogspot.com/ Web Services - sharing data between client and server Dealing a lot with web services a friend of mine (Ehsan Samani) and I ran into another issue: when we move data from web services to the smart client and back the classes created by the proxy are not identical with the ones on the web services side. If the types we create are really complex then the code associated is complex too. Sharing the code between...
6
2840
by: Marc Castrechini | last post by:
This is a classic double hop delegation issue, however its the first time we are setting this up so we are doing something incorrectly. If we run through the IDE or using a localhost path on the web server the command succeeds. However, if we use the servername or ip through IIS it fails. For this reason we know we have permissions setup correctly on the file server. Can anyone identify what we could possibly be doing wrong here: ...
3
3496
by: Patrick | last post by:
Hello I have the following scenario - SQL 2005 server (serversql) - Windows 2003 with IIS (serveriis) - Windows 2003 ADS (serverads) I want to connect to an intranet application using NTML with impersonation and delegation. so for this I made the following change in web.config <identity impersonate="true"/>
2
10238
by: Ognjen Bezanov | last post by:
Hello! Just to ask, is it possible to make a static dictionary in python. So that the keys in the dictionary cannot be removed, changed or new ones added, but the value pairs can. Is this possible with python? thanks,
1
1652
by: =?Utf-8?B?U2llZ2ZyaWVkIEhlaW50emU=?= | last post by:
I'm trying to follow Luca Bolognese's example from http://www.microsoft.com/emea/msdn/spotlight/sessionh.aspx?videoid=716 but the following code works for him but not me. VS2008 says there is no System.Data.Linq! I tried live searching for a simple example that worked but could not find one. Can someone tell me how to make Luca's example work or point me to an example that does work? Thanks,
0
9590
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
9424
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
10223
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
10051
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
10000
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
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3571
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.