Beruflich Dokumente
Kultur Dokumente
6.1 How can I include an Asp.NET page in many other Asp.Net pages so
that I don't need to rewrite the code?
One of the approaches is to write and use a UserControl. You can define the user interface, handle events and
expose properties in a UserControl, and then mark a reference and reuse these Controls in any page of your
Web application.
6.2 Is there anything similar to web templates in ASP that I can use in
ASP.Net?
In ASP.NET, you would typically use a User Control to create reusable controls.
6.3 Are there any settings on the application level to make certain
elements appear on every page without having to manually insert code
or insert UserControls?
You can use HttpHandlers and/or HttpModules to insert information on all pages transparently. Check out
VB.NET
C#
Drag and drop User Control and set the source property.
uc1.ascx:
<asp:Label runat="server" text="uc1" ID="Label1" />
<asp:Panel runat="server" id="p1" >Panel UC1</asp:Panel>
uc2.ascx:
<br><asp:Label runat="server" text="uc2" ID="Label1" />
VB.NET
C#
6.6 I have a function inside of the .ascx file. How can I call it from the
web application page(the .aspx file)?
All you need to do is give your user control an ID in the aspx. e.g.
myUC.writeData(...)
C#
myUC.writeData(...)
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
<P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
On button Click
VB.NET
Label1.Text = "Hello"
C#
Label1.Text = "Hello" ;
VB.NET
C#
In the .ascx:
In .aspx
VB.NET
Dim UC As UserControl
Dim imgUC As System.Web.UI.WebControls.Image
UC = Page.FindControl("UCImage1")
imgUC = UC.FindControl("Image1")
imgUC.ImageUrl = "b2346.jpg"
C#
UserControl UC ;
System.Web.UI.WebControls.Image imgUC ;
UC = (UserControl)Page.FindControl("UCImage1");
imgUC =(System.Web.UI.WebControls.Image)UC.FindControl("Image1");
imgUC.ImageUrl = "b2346.jpg";