User Controls, Code-behind & passing values using custom properties in VB.NET This simple example demonstrates how to use a User Control and Code Behinds to passvalues using Custom Properties to the code-behind form.This simple example demonstrates how to use a User Control and Code Behinds to pass values using Custom Properties to the code-behind form. ASPX page <%@ Page Language="VB"%> <%@ Register TagPrefix="Prefix" TagName="Test" src="uc_test.ascx"%> <HTML> <HEAD> <TITLE></TITLE> </HEAD> <BODY> <Prefix:Test CustomProp="No" CustomProp2="Yes" id=Test1 runat="server" /> </BODY> </HTML> User Control (uc_test.ascx)
<%@ Control Language="VB" Inherits="uc_test" SRC="uc_test.ascx.vb"%> Code-behind form (uc_test.ascx.vb Imports System Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.HtmlControls Imports System.Data Imports System.Data.SqlClient Imports System.Configuration
Public Class uc_test : Inherits System.Web.UI.UserControl
Dim _CustomProp as string Dim _CustomProp2 as string
Public Property CustomProp() As String Get Return _CustomProp End Get Set _CustomProp = value End Set End Property
Public Property CustomProp2() As String Get Return _CustomProp2 End Get Set _CustomProp2 = value End Set End Property
private Sub Page_Load(Sender as object, e as System.EventArgs)
If CustomProp = "Yes" Then Response.Write ("<BR>The value of my custom property (CustomProp) is: " & _CustomProp) Else ' GetDr( Request.UrlReferrer.ToString()) Response.Write ("<BR>The value of my custom property (CustomProp2) is: " & _CustomProp2) End If
End Sub
Private Function GetDr(sqlText as string) sqlText = "INSERT INTO TABLES(columns)values('" & sqlText & "')" dim sqlConn as SqlConnection = new SqlConnection(ConnectionString()) Dim sqlCmd as SqlCommand = new SqlCommand(sqlText,sqlConn) sqlCmd.Connection.Open() sqlCmd.ExecuteNonQuery() sqlCmd.Connection.Close() End Function
Private Function ConnectionString() as string dim myConn as string = ConfigurationSettings.AppSettings("DSN") return myConn End Function
Private Sub Page_Init(Sender as object, e as System.EventArgs )
End Sub End Class Web.Config <configuration> <appSettings> <add key="DSN_NorthWind" value="server=(local)\NetSDK;database=NorthWind;Trusted_Connection=yes" /> <add key="DSN_pubs" value="server=(local)\NetSDK;database=pubs;Trusted_Connection=yes" /> </appSettings> </configuration> | DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP.NET Articles More By aspfree developerWorks - FREE Tools! | Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. FREE! Go There Now!
| | | | As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
| | | | Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
| | | | Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
| | | | You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online. FREE! Go There Now!
| | | | Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
| | | | Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager. FREE! Go There Now!
| | | | Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |