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! | The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
| | | | As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
| | | | Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools. FREE! Go There Now!
| | | | Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right." FREE! Go There Now!
| | | | CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP. FREE! Go There Now!
| | | | Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users. FREE! Go There Now!
| | | | Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered! 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!
| | | | Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |