User Controls, Code-behind and passing values using custom properties in VB.NET

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.

Contributed by
Rating: 2 stars2 stars2 stars2 stars2 stars / 20
September 23, 2001
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

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>

blog comments powered by Disqus
ASP.NET ARTICLES

- Implementing ASP.NET 4.0 Page.MetaDescriptio...
- ASP.Net Development Tips
- Intro to Sessions in ASP.Net
- Google Maps API Introduction in ASP.NET usin...
- Creating an ASP.NET 3.5 Gridview Image Galle...
- Encrypt QueryString in ASP.NET 3.5 using VB....
- ASP.NET 3.5 Drop Down List Controls
- Connect to Access Database with ASP.Net
- Secure Audio Streaming with ASP.Net and Flash
- Dynamic Sitemap and Navigation in ASP.Net
- Implement Gzip and Deflate Compression in AS...
- Run ASP.Net in Ubuntu with Apache
- ASP.Net Mono Website Contact Forms
- ASP.Net URL Rewriting Methods
- Murach`s ASP.NET 4 Web Programming with C# 2...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials