SlideShare a Scribd company logo
1 of 27
• What are user controls
• Types of User Controls
• Creating User Controls
• Defining Properties in User Controls
• Adding a User Control to a Page
• Defining User Control Events
• Passing Information with Events
• Dynamic Graphics
A user control is a file that you create that
contains other ASP.NET controls and code
grouped together to provide common
functionality.

The user control can then be used on
different pages within a Web Site.

User Contols are created as .ascx file. An
.ascx file is similar to the .aspx file and can
have its own code behind page.
To enable reuse the .ascx and .cs file must
be included in each project that requires the
user control. For this reason, user controls
are typically reserved for reuse within a given
site. If you need reuse between sites, you
should consider using Web Server Controls
The .ascx file for a user control begins with a
<%@ Control %> directive instead of
a <%@ Page %> directive.

Their code-behind files inherit from the
System.Web.UI.UserControl class

User controls can’t be requested directly by a
web browser. Instead, they must be
embedded inside other web pages
Conceptually, two types of user controls exist:

• Independent
• Integrated

Independent user controls don’t interact with the rest of
the code on your form

Integrated user controls can be very useful for breaking
down a large application into smaller, more manageable
chunks you integrate these user controls to a page / form
to develop a feature. Integrated user controls interact in
one way or another with the web page that hosts them.
User Control File HyperlinkControl.ascx

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile=“HyperlinkControl.ascx.cs" Inherits=“HyperlinkControl" %>
<div>
Products:<br />
<asp:HyperLink id="lnkBooks" runat="server"
NavigateUrl="MenuHost.aspx?product=Books">Books
</asp:HyperLink><br />
<asp:HyperLink id="lnkToys" runat="server"
NavigateUrl="MenuHost.aspx?product=Toys">Toys
</asp:HyperLink><br />
<asp:HyperLink id="lnkSports" runat="server"
NavigateUrl="MenuHost.aspx?product=Sports">Sports
</asp:HyperLink><br />
<asp:HyperLink id="lnkFurniture" runat="server"
NavigateUrl="MenuHost.aspx?product=Furniture">Furniture
</asp:HyperLink>
</div>
Web Page MenuHost.aspx
<%@ Page Language="C#" AutoEventWireup="true »
CodeFile="MenuHost.aspx.cs" Inherits="MenuHost"%>
<%@ Register TagPrefix="apress" TagName=“HyperlinkControl"
Src=“HyperlinkControl.ascx" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Menu Host</title>
</head>
<body>
<form id="form1" runat="server">
<div>
        <table>
        <tr>
        <td><apress:HyperlinkControl id="Menu1" runat="server" /></td>
        <td><asp:Label id="lblSelection" runat="server" /></td>
        </tr>
        </table>
</div>
</form>
</body>
</html>
Code Behind MenuHost.aspx.cs



protected void Page_Load(Object sender, EventArgs e)
{
if (Request.Params["product"] != null)
{
lblSelection.Text = "You chose: ";
lblSelection.Text += Request.Params["product"];
}
}
An ordinary HyperLink control that doesn’t have any associated
server-side code because the HyperLink control doesn’t fire an
event when the link is clicked.

Instead, you’ll need to use the LinkButton. The LinkButton fires
the Click event, which the LinkMenuControl can intercept, and
then raises the LinkClicked event to the web page.

Every page in the website can then include the same LinkMenu
user control, enabling painless website navigation with no need
to worry about frames.


This LinkMenu user control can handle the events for all the
buttons and then run the appropriate Response.Redirect() code
to move to another web page.
In the following example, you’ll see a version of the LinkMenu
Control that uses events. Instead of navigating directly to the
appropriate page when the user clicks a button, the control
raises an event, which the web page can choose to handle.
 // Declaring the LinkClicked event
public partial class LinkMenuControl : System.Web.UI.UserControl
{
public event EventHandler LinkClicked;
...
}

 // Defining the LinkClicked event
protected void lnk_Click(object sender, EventArgs e)
{ ... }

// Raising the LinkClicked event
LinkClicked(this, EventArgs.Empty);
User Control File LinkMenuControl.ascx

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="LinkMenuControl.ascx.cs" Inherits="LinkMenuControl" %>

<div>
<asp:LinkButton ID="lnkBooks" runat="server"
OnClick="lnk_Click">Books</asp:LinkButton><br />

<asp:LinkButton ID="lnkToys" runat="server"
OnClick="lnk_Click">Toys</asp:LinkButton><br />

<asp:LinkButton ID="lnkSports" runat="server"
OnClick="lnk_Click">Sports</asp:LinkButton><br />

<asp:LinkButton ID="lnkFurniture" runat="server"
OnClick="lnk_Click">Furniture</asp:LinkButton>

</div>
Code Behind File LinkMenuControl.ascx.cs


public partial class LinkMenuControl : System.Web.UI.UserControl
{
public event EventHandler LinkClicked;

protected void lnk_Click(object sender, EventArgs e)
{
// One of the LinkButton controls has been clicked.
// Raise an event to the page.
if (LinkClicked != null)
{
LinkClicked(this, EventArgs.Empty);
}
}
}
Web Page LinkMenuHost.aspx

<%@ Page Language="C#" AutoEventWireup="true »
CodeFile=“LinkMenuHost.aspx.cs" Inherits=“LinkMenuHost"%>
<%@ Register TagPrefix="apress" TagName="LinkMenuControl"
Src="LinkMenu.ascx" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<body>
.
.
.
<apress:LinkMenuControl id="Menu1" runat="server"
OnLinkClicked="LinkClicked" />
.
.
.
</body>
</html>
Code Behind LinkMenuHost.aspx.cs



protected void LinkClicked(object sender, EventArgs e)
{
lblClick.Text = "Click detected.";
}
In the current LinkMenu example, no custom
information is passed along with the event. When
the LinkClicked event occurs, the web page has no
way of knowing what link was clicked.

The trick is to switch from the LinkButton.Click
event to the LinkButton.Command event. The
Command event automatically gets the
CommandArgument that’s defined in the tag.
Also to convey additional information that relates to the event, you
need to create a custom class that derives from EventArgs.

The .NET standard for events specifies that every event should use
two parameters. The first one provides a reference to the control that
sent the event, while the second incorporates any additional
information. This additional information is wrapped into a custom
EventArgs object, which inherits from the System.EventArgs class

The LinkClickedEventArgs class that follows allows the LinkMenu
user control to pass the URL that the user selected through a Url
property. It also provides a Cancel property. If set to true, the user
control will stop its processing immediately. But if Cancel remains
false (the default), the user control will send the user to the new page.
public class LinkClickedEventArgs : EventArgs
{
public string Url {get; set;}
public bool Cancel {get; set;}
public LinkClickedEventArgs(string url)
{
Url = url;
}
}
To use this custom EventArgs class, you need to modify the
definition of the LinkClicked event so it uses the
LinkClickedEventArgs object:

// Declaring the LinkClicked event
public event EventHandler<LinkClickedEventArgs>
LinkClicked;

// Defining the LinkClicked event
LinkClickedEventArgs args = new
LinkClickedEventArgs((string)e.CommandArgument);

// Raising the LinkClicked event
LinkClicked(this, args);
User Control File LinkMenuControl1.ascx
<asp:LinkButton ID="lnkBooks" runat="server"
CommandArgument="Menu2Host.aspx?product=Books"
OnCommand="lnk_Command">Books
</asp:LinkButton><br />
<asp:LinkButton ID="lnkToys" runat="server"
CommandArgument="Menu2Host.aspx?product=Toys"
OnCommand="lnk_Command">Toys
</asp:LinkButton><br />
<asp:LinkButton ID="lnkSports" runat="server"
CommandArgument="Menu2Host.aspx?product=Sports"
OnCommand="lnk_Command">Sports
</asp:LinkButton><br />
<asp:LinkButton ID="lnkFurniture" runat="server"
CommandArgument="Menu2Host.aspx?product=Furniture"
OnCommand="lnk_Command">
Furniture</asp:LinkButton>
Code Behind File LinkMenuControl.ascx.cs

public partial class LinkMenuControl1 : System.Web.UI.UserControl
{
public event EventHandler<LinkClickedEventArgs> LinkClicked;
protected void lnk_Command(object sender, CommandEventArgs e)
{

if (LinkClicked != null)
{

// Pass along the link information.
LinkClickedEventArgs args =
new LinkClickedEventArgs((string)e.CommandArgument);

LinkClicked(this, args);
if (!args.Cancel)
{
Response.Redirect(args.Url);
}
}
Web Page LinkMenuHost.aspx

<%@ Page Language="C#" AutoEventWireup="true »
CodeFile=“LinkMenuHost.aspx.cs" Inherits=“LinkMenuHost"%>
<%@ Register TagPrefix="apress" TagName="LinkMenuControl"
Src="LinkMenu.ascx" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<body>
.
.
.
<apress:LinkMenuControl1 id="Menu1" runat="server"
OnLinkClicked="LinkClicked" />
.
.
.
</body>
</html>
Code Behind LinkMenuHost.aspx.cs

protected void LinkClicked(object sender, LinkClickedEventArgs e)
{
if (e.Url == "Menu2Host.aspx?product=Furniture")
{
lblClick.Text = "This link is not allowed.";
e.Cancel = true;
}
else
{
Response.Redirect(e.Url);
}
}
 protected void Page_Load(object sender, EventArgs e)
    {
      if (Request.Params["product"] != null)
      {
          lblSelection.Text = "You chose: ";
          lblSelection.Text += Request.Params["product"];
      }
    }
One of the features of the .NET Framework is GDI+, a set of
classes designed for drawing images.

You need to follow four basic steps when using GDI+.

•   First, you have to create an in-memory bitmap.

•   To create the bitmap, declare a new instance of the
    System.Drawing.Bitmap class.

•   You must specify the height and width of the image in
•   pixels.

•   The next step is to create a GDI+ graphics context for the
    image, which is represented by a System.Drawing.Graphics
    object.

•   To create a Graphics object from an existing Bitmap object, you
    just use the static Graphics.FromImage() method,
•   Now use the methods of the Graphics class. The methods that begin
    with the word Draw draw outlines, while the methods that begin with
    the word Fill draw solid regions

•   When calling the Graphics class methods, you need to specify several
    parameters to indicate the pixel coordinates for what you want to draw.

•   You need to specify either a Brush or a Pen object when you draw
    most content. (Both of these classes are defined in the
    System.Drawing namespace, alongside the Graphics class.)

•   Once the image is complete, you can send it to the browser using the
    Image.Save() method.

•   Finally, you should explicitly release your image and graphics context
    when you’re finished, because both hold onto some unmanaged
    resources that might not be released right away if you don’t
protected void Page_Load(Object sender, EventArgs e)
{
Bitmap image = new Bitmap(300, 50);

Graphics g = Graphics.FromImage(image);

g.FillRectangle(Brushes.LightYellow, 0, 0, 300, 50);
g.DrawRectangle(Pens.Red, 0, 0, 299, 49);

Font font = new Font("Alba Super", 20, FontStyle.Regular);
g.DrawString("This is a test.", font, Brushes.Blue, 10, 0);

System.Drawing.Image icon = Image.FromFile(Server.MapPath("smiley.gif"));
g.DrawImageUnscaled(icon, 240, 0);

image.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Gif);

g.Dispose();
image.Dispose();
The Image.Save() approach demonstrated so far has one
problem. When you save an image to the response stream,
you overwrite whatever information ASP.NET would other
wise use.

 If you have a web page that includes other content and
controls, this content won’t appear at all in the final web
page. Instead, the dynamically rendered graphics replace it.

Fortunately, this has a simple solution: you can link to a
dynamically generated image using the <img> tag or the
Image web control. But instead of linking your image to a
fixed image file, link it to the .aspx file that generates the
picture.
The full Image.ImageUrl thus becomes
GraphicalText.aspx?Name=Joe%20Brown, as shown here:


<asp:Image id="Image1" runat="server"
ImageUrl="GraphicalText.aspx?Name=Joe%20Brown"></
asp:Image>


string name = Request.QueryString["Name"];

g.DrawString(name, font, Brushes.Blue, 10, 0);

More Related Content

What's hot

Watson IoT Platform Embedded Rules Concepts & APIs Overview
Watson IoT Platform Embedded Rules Concepts & APIs OverviewWatson IoT Platform Embedded Rules Concepts & APIs Overview
Watson IoT Platform Embedded Rules Concepts & APIs Overviewsmithson.martin
 
Lightning Components Workshop
Lightning Components WorkshopLightning Components Workshop
Lightning Components WorkshopGordon Bockus
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life CycleAbhishek Sur
 
Watson IoT Action Manager Concepts & API Overview
Watson IoT Action Manager Concepts & API OverviewWatson IoT Action Manager Concepts & API Overview
Watson IoT Action Manager Concepts & API Overviewsmithson.martin
 
State management in asp
State management in aspState management in asp
State management in aspIbrahim MH
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introductionTomi Juhola
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828Viral Patel
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.NetHitesh Santani
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20HUST
 
Rapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and FirebaseRapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and FirebasePeter Friese
 
REST Architecture with use case and example
REST Architecture with use case and exampleREST Architecture with use case and example
REST Architecture with use case and exampleShailesh singh
 
Desenvolvimento web com Ruby on Rails (extras)
Desenvolvimento web com Ruby on Rails (extras)Desenvolvimento web com Ruby on Rails (extras)
Desenvolvimento web com Ruby on Rails (extras)Joao Lucas Santana
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controlsRaed Aldahdooh
 
Android ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codesAndroid ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codesAravindharamanan S
 
Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentRob Windsor
 

What's hot (20)

Watson IoT Platform Embedded Rules Concepts & APIs Overview
Watson IoT Platform Embedded Rules Concepts & APIs OverviewWatson IoT Platform Embedded Rules Concepts & APIs Overview
Watson IoT Platform Embedded Rules Concepts & APIs Overview
 
Lightning Components Workshop
Lightning Components WorkshopLightning Components Workshop
Lightning Components Workshop
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
 
Watson IoT Action Manager Concepts & API Overview
Watson IoT Action Manager Concepts & API OverviewWatson IoT Action Manager Concepts & API Overview
Watson IoT Action Manager Concepts & API Overview
 
Mixpanel
MixpanelMixpanel
Mixpanel
 
State management in asp
State management in aspState management in asp
State management in asp
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828
 
Asp.net
Asp.netAsp.net
Asp.net
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
 
jQuery Ajax
jQuery AjaxjQuery Ajax
jQuery Ajax
 
Mockito junit
Mockito junitMockito junit
Mockito junit
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20
 
Mashup
MashupMashup
Mashup
 
Rapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and FirebaseRapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and Firebase
 
REST Architecture with use case and example
REST Architecture with use case and exampleREST Architecture with use case and example
REST Architecture with use case and example
 
Desenvolvimento web com Ruby on Rails (extras)
Desenvolvimento web com Ruby on Rails (extras)Desenvolvimento web com Ruby on Rails (extras)
Desenvolvimento web com Ruby on Rails (extras)
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
 
Android ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codesAndroid ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codes
 
Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part Development
 

Viewers also liked

ASP.NET 04 - Additional Web Server Controls
ASP.NET 04 - Additional Web Server ControlsASP.NET 04 - Additional Web Server Controls
ASP.NET 04 - Additional Web Server ControlsRandy Connolly
 
Introduction of Ghost CMSGhost cms
Introduction of Ghost CMSGhost cmsIntroduction of Ghost CMSGhost cms
Introduction of Ghost CMSGhost cmsKhademulBasher
 
Mobile ASP.Net Web Forms - Making the impossible possible | FalafelCON 2014
Mobile ASP.Net Web Forms - Making the impossible possible | FalafelCON 2014Mobile ASP.Net Web Forms - Making the impossible possible | FalafelCON 2014
Mobile ASP.Net Web Forms - Making the impossible possible | FalafelCON 2014FalafelSoftware
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpcasestudyhelp
 
Introduction of VS2012 IDE and ASP.NET Controls
Introduction of VS2012 IDE and ASP.NET ControlsIntroduction of VS2012 IDE and ASP.NET Controls
Introduction of VS2012 IDE and ASP.NET ControlsKhademulBasher
 

Viewers also liked (6)

ASP.NET 04 - Additional Web Server Controls
ASP.NET 04 - Additional Web Server ControlsASP.NET 04 - Additional Web Server Controls
ASP.NET 04 - Additional Web Server Controls
 
Introduction of Ghost CMSGhost cms
Introduction of Ghost CMSGhost cmsIntroduction of Ghost CMSGhost cms
Introduction of Ghost CMSGhost cms
 
Mobile ASP.Net Web Forms - Making the impossible possible | FalafelCON 2014
Mobile ASP.Net Web Forms - Making the impossible possible | FalafelCON 2014Mobile ASP.Net Web Forms - Making the impossible possible | FalafelCON 2014
Mobile ASP.Net Web Forms - Making the impossible possible | FalafelCON 2014
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) help
 
Introducing Cascading Style Sheets
Introducing Cascading Style SheetsIntroducing Cascading Style Sheets
Introducing Cascading Style Sheets
 
Introduction of VS2012 IDE and ASP.NET Controls
Introduction of VS2012 IDE and ASP.NET ControlsIntroduction of VS2012 IDE and ASP.NET Controls
Introduction of VS2012 IDE and ASP.NET Controls
 

Similar to Chapter 11

User controls
User controlsUser controls
User controlsaspnet123
 
13 asp.net session19
13 asp.net session1913 asp.net session19
13 asp.net session19Vivek chan
 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXIMC Institute
 
ASP.Net Presentation Part1
ASP.Net Presentation Part1ASP.Net Presentation Part1
ASP.Net Presentation Part1Neeraj Mathur
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questionsAkhil Mittal
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17Vivek chan
 
Asp.net By Durgesh Singh
Asp.net By Durgesh SinghAsp.net By Durgesh Singh
Asp.net By Durgesh Singhimdurgesh
 
Interoperable Component Patterns
Interoperable Component PatternsInteroperable Component Patterns
Interoperable Component PatternsMatthew Beale
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMohammad Shaker
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentChui-Wen Chiu
 
Chanhao Jiang And David Wei Presentation Quickling Pagecache
Chanhao Jiang And David Wei Presentation Quickling PagecacheChanhao Jiang And David Wei Presentation Quickling Pagecache
Chanhao Jiang And David Wei Presentation Quickling PagecacheAjax Experience 2009
 

Similar to Chapter 11 (20)

User controls
User controlsUser controls
User controls
 
Asp PPT (.NET )
Asp PPT (.NET )Asp PPT (.NET )
Asp PPT (.NET )
 
13 asp.net session19
13 asp.net session1913 asp.net session19
13 asp.net session19
 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAX
 
ASP.Net Presentation Part1
ASP.Net Presentation Part1ASP.Net Presentation Part1
ASP.Net Presentation Part1
 
2310 b 05
2310 b 052310 b 05
2310 b 05
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17
 
Managing states
Managing statesManaging states
Managing states
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
 
Ajax and ASP.NET AJAX
Ajax and ASP.NET AJAXAjax and ASP.NET AJAX
Ajax and ASP.NET AJAX
 
Asp.net By Durgesh Singh
Asp.net By Durgesh SinghAsp.net By Durgesh Singh
Asp.net By Durgesh Singh
 
Interoperable Component Patterns
Interoperable Component PatternsInteroperable Component Patterns
Interoperable Component Patterns
 
ASP.NET - Web Programming
ASP.NET - Web ProgrammingASP.NET - Web Programming
ASP.NET - Web Programming
 
Asp
AspAsp
Asp
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
 
Chanhao Jiang And David Wei Presentation Quickling Pagecache
Chanhao Jiang And David Wei Presentation Quickling PagecacheChanhao Jiang And David Wei Presentation Quickling Pagecache
Chanhao Jiang And David Wei Presentation Quickling Pagecache
 
WPF Fundamentals
WPF FundamentalsWPF Fundamentals
WPF Fundamentals
 

More from application developer (20)

Chapter 26
Chapter 26Chapter 26
Chapter 26
 
Chapter 25
Chapter 25Chapter 25
Chapter 25
 
Chapter 23
Chapter 23Chapter 23
Chapter 23
 
Assignment
AssignmentAssignment
Assignment
 
Next step job board (Assignment)
Next step job board (Assignment)Next step job board (Assignment)
Next step job board (Assignment)
 
Chapter 19
Chapter 19Chapter 19
Chapter 19
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
Week 3 assignment
Week 3 assignmentWeek 3 assignment
Week 3 assignment
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
C # test paper
C # test paperC # test paper
C # test paper
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
 
Chapter 8 part2
Chapter 8   part2Chapter 8   part2
Chapter 8 part2
 
Chapter 8 part1
Chapter 8   part1Chapter 8   part1
Chapter 8 part1
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 

Recently uploaded (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

Chapter 11

  • 1. • What are user controls • Types of User Controls • Creating User Controls • Defining Properties in User Controls • Adding a User Control to a Page • Defining User Control Events • Passing Information with Events • Dynamic Graphics
  • 2. A user control is a file that you create that contains other ASP.NET controls and code grouped together to provide common functionality. The user control can then be used on different pages within a Web Site. User Contols are created as .ascx file. An .ascx file is similar to the .aspx file and can have its own code behind page.
  • 3. To enable reuse the .ascx and .cs file must be included in each project that requires the user control. For this reason, user controls are typically reserved for reuse within a given site. If you need reuse between sites, you should consider using Web Server Controls
  • 4. The .ascx file for a user control begins with a <%@ Control %> directive instead of a <%@ Page %> directive. Their code-behind files inherit from the System.Web.UI.UserControl class User controls can’t be requested directly by a web browser. Instead, they must be embedded inside other web pages
  • 5. Conceptually, two types of user controls exist: • Independent • Integrated Independent user controls don’t interact with the rest of the code on your form Integrated user controls can be very useful for breaking down a large application into smaller, more manageable chunks you integrate these user controls to a page / form to develop a feature. Integrated user controls interact in one way or another with the web page that hosts them.
  • 6. User Control File HyperlinkControl.ascx <%@ Control Language="C#" AutoEventWireup="true" CodeFile=“HyperlinkControl.ascx.cs" Inherits=“HyperlinkControl" %> <div> Products:<br /> <asp:HyperLink id="lnkBooks" runat="server" NavigateUrl="MenuHost.aspx?product=Books">Books </asp:HyperLink><br /> <asp:HyperLink id="lnkToys" runat="server" NavigateUrl="MenuHost.aspx?product=Toys">Toys </asp:HyperLink><br /> <asp:HyperLink id="lnkSports" runat="server" NavigateUrl="MenuHost.aspx?product=Sports">Sports </asp:HyperLink><br /> <asp:HyperLink id="lnkFurniture" runat="server" NavigateUrl="MenuHost.aspx?product=Furniture">Furniture </asp:HyperLink> </div>
  • 7. Web Page MenuHost.aspx <%@ Page Language="C#" AutoEventWireup="true » CodeFile="MenuHost.aspx.cs" Inherits="MenuHost"%> <%@ Register TagPrefix="apress" TagName=“HyperlinkControl" Src=“HyperlinkControl.ascx" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Menu Host</title> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td><apress:HyperlinkControl id="Menu1" runat="server" /></td> <td><asp:Label id="lblSelection" runat="server" /></td> </tr> </table> </div> </form> </body> </html>
  • 8. Code Behind MenuHost.aspx.cs protected void Page_Load(Object sender, EventArgs e) { if (Request.Params["product"] != null) { lblSelection.Text = "You chose: "; lblSelection.Text += Request.Params["product"]; } }
  • 9. An ordinary HyperLink control that doesn’t have any associated server-side code because the HyperLink control doesn’t fire an event when the link is clicked. Instead, you’ll need to use the LinkButton. The LinkButton fires the Click event, which the LinkMenuControl can intercept, and then raises the LinkClicked event to the web page. Every page in the website can then include the same LinkMenu user control, enabling painless website navigation with no need to worry about frames. This LinkMenu user control can handle the events for all the buttons and then run the appropriate Response.Redirect() code to move to another web page.
  • 10. In the following example, you’ll see a version of the LinkMenu Control that uses events. Instead of navigating directly to the appropriate page when the user clicks a button, the control raises an event, which the web page can choose to handle. // Declaring the LinkClicked event public partial class LinkMenuControl : System.Web.UI.UserControl { public event EventHandler LinkClicked; ... } // Defining the LinkClicked event protected void lnk_Click(object sender, EventArgs e) { ... } // Raising the LinkClicked event LinkClicked(this, EventArgs.Empty);
  • 11. User Control File LinkMenuControl.ascx <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LinkMenuControl.ascx.cs" Inherits="LinkMenuControl" %> <div> <asp:LinkButton ID="lnkBooks" runat="server" OnClick="lnk_Click">Books</asp:LinkButton><br /> <asp:LinkButton ID="lnkToys" runat="server" OnClick="lnk_Click">Toys</asp:LinkButton><br /> <asp:LinkButton ID="lnkSports" runat="server" OnClick="lnk_Click">Sports</asp:LinkButton><br /> <asp:LinkButton ID="lnkFurniture" runat="server" OnClick="lnk_Click">Furniture</asp:LinkButton> </div>
  • 12. Code Behind File LinkMenuControl.ascx.cs public partial class LinkMenuControl : System.Web.UI.UserControl { public event EventHandler LinkClicked; protected void lnk_Click(object sender, EventArgs e) { // One of the LinkButton controls has been clicked. // Raise an event to the page. if (LinkClicked != null) { LinkClicked(this, EventArgs.Empty); } } }
  • 13. Web Page LinkMenuHost.aspx <%@ Page Language="C#" AutoEventWireup="true » CodeFile=“LinkMenuHost.aspx.cs" Inherits=“LinkMenuHost"%> <%@ Register TagPrefix="apress" TagName="LinkMenuControl" Src="LinkMenu.ascx" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <body> . . . <apress:LinkMenuControl id="Menu1" runat="server" OnLinkClicked="LinkClicked" /> . . . </body> </html>
  • 14. Code Behind LinkMenuHost.aspx.cs protected void LinkClicked(object sender, EventArgs e) { lblClick.Text = "Click detected."; }
  • 15. In the current LinkMenu example, no custom information is passed along with the event. When the LinkClicked event occurs, the web page has no way of knowing what link was clicked. The trick is to switch from the LinkButton.Click event to the LinkButton.Command event. The Command event automatically gets the CommandArgument that’s defined in the tag.
  • 16. Also to convey additional information that relates to the event, you need to create a custom class that derives from EventArgs. The .NET standard for events specifies that every event should use two parameters. The first one provides a reference to the control that sent the event, while the second incorporates any additional information. This additional information is wrapped into a custom EventArgs object, which inherits from the System.EventArgs class The LinkClickedEventArgs class that follows allows the LinkMenu user control to pass the URL that the user selected through a Url property. It also provides a Cancel property. If set to true, the user control will stop its processing immediately. But if Cancel remains false (the default), the user control will send the user to the new page.
  • 17. public class LinkClickedEventArgs : EventArgs { public string Url {get; set;} public bool Cancel {get; set;} public LinkClickedEventArgs(string url) { Url = url; } }
  • 18. To use this custom EventArgs class, you need to modify the definition of the LinkClicked event so it uses the LinkClickedEventArgs object: // Declaring the LinkClicked event public event EventHandler<LinkClickedEventArgs> LinkClicked; // Defining the LinkClicked event LinkClickedEventArgs args = new LinkClickedEventArgs((string)e.CommandArgument); // Raising the LinkClicked event LinkClicked(this, args);
  • 19. User Control File LinkMenuControl1.ascx <asp:LinkButton ID="lnkBooks" runat="server" CommandArgument="Menu2Host.aspx?product=Books" OnCommand="lnk_Command">Books </asp:LinkButton><br /> <asp:LinkButton ID="lnkToys" runat="server" CommandArgument="Menu2Host.aspx?product=Toys" OnCommand="lnk_Command">Toys </asp:LinkButton><br /> <asp:LinkButton ID="lnkSports" runat="server" CommandArgument="Menu2Host.aspx?product=Sports" OnCommand="lnk_Command">Sports </asp:LinkButton><br /> <asp:LinkButton ID="lnkFurniture" runat="server" CommandArgument="Menu2Host.aspx?product=Furniture" OnCommand="lnk_Command"> Furniture</asp:LinkButton>
  • 20. Code Behind File LinkMenuControl.ascx.cs public partial class LinkMenuControl1 : System.Web.UI.UserControl { public event EventHandler<LinkClickedEventArgs> LinkClicked; protected void lnk_Command(object sender, CommandEventArgs e) { if (LinkClicked != null) { // Pass along the link information. LinkClickedEventArgs args = new LinkClickedEventArgs((string)e.CommandArgument); LinkClicked(this, args); if (!args.Cancel) { Response.Redirect(args.Url); } }
  • 21. Web Page LinkMenuHost.aspx <%@ Page Language="C#" AutoEventWireup="true » CodeFile=“LinkMenuHost.aspx.cs" Inherits=“LinkMenuHost"%> <%@ Register TagPrefix="apress" TagName="LinkMenuControl" Src="LinkMenu.ascx" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <body> . . . <apress:LinkMenuControl1 id="Menu1" runat="server" OnLinkClicked="LinkClicked" /> . . . </body> </html>
  • 22. Code Behind LinkMenuHost.aspx.cs protected void LinkClicked(object sender, LinkClickedEventArgs e) { if (e.Url == "Menu2Host.aspx?product=Furniture") { lblClick.Text = "This link is not allowed."; e.Cancel = true; } else { Response.Redirect(e.Url); } } protected void Page_Load(object sender, EventArgs e) { if (Request.Params["product"] != null) { lblSelection.Text = "You chose: "; lblSelection.Text += Request.Params["product"]; } }
  • 23. One of the features of the .NET Framework is GDI+, a set of classes designed for drawing images. You need to follow four basic steps when using GDI+. • First, you have to create an in-memory bitmap. • To create the bitmap, declare a new instance of the System.Drawing.Bitmap class. • You must specify the height and width of the image in • pixels. • The next step is to create a GDI+ graphics context for the image, which is represented by a System.Drawing.Graphics object. • To create a Graphics object from an existing Bitmap object, you just use the static Graphics.FromImage() method,
  • 24. Now use the methods of the Graphics class. The methods that begin with the word Draw draw outlines, while the methods that begin with the word Fill draw solid regions • When calling the Graphics class methods, you need to specify several parameters to indicate the pixel coordinates for what you want to draw. • You need to specify either a Brush or a Pen object when you draw most content. (Both of these classes are defined in the System.Drawing namespace, alongside the Graphics class.) • Once the image is complete, you can send it to the browser using the Image.Save() method. • Finally, you should explicitly release your image and graphics context when you’re finished, because both hold onto some unmanaged resources that might not be released right away if you don’t
  • 25. protected void Page_Load(Object sender, EventArgs e) { Bitmap image = new Bitmap(300, 50); Graphics g = Graphics.FromImage(image); g.FillRectangle(Brushes.LightYellow, 0, 0, 300, 50); g.DrawRectangle(Pens.Red, 0, 0, 299, 49); Font font = new Font("Alba Super", 20, FontStyle.Regular); g.DrawString("This is a test.", font, Brushes.Blue, 10, 0); System.Drawing.Image icon = Image.FromFile(Server.MapPath("smiley.gif")); g.DrawImageUnscaled(icon, 240, 0); image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); g.Dispose(); image.Dispose();
  • 26. The Image.Save() approach demonstrated so far has one problem. When you save an image to the response stream, you overwrite whatever information ASP.NET would other wise use. If you have a web page that includes other content and controls, this content won’t appear at all in the final web page. Instead, the dynamically rendered graphics replace it. Fortunately, this has a simple solution: you can link to a dynamically generated image using the <img> tag or the Image web control. But instead of linking your image to a fixed image file, link it to the .aspx file that generates the picture.
  • 27. The full Image.ImageUrl thus becomes GraphicalText.aspx?Name=Joe%20Brown, as shown here: <asp:Image id="Image1" runat="server" ImageUrl="GraphicalText.aspx?Name=Joe%20Brown"></ asp:Image> string name = Request.QueryString["Name"]; g.DrawString(name, font, Brushes.Blue, 10, 0);