Showing posts with label Show all posts
Showing posts with label Show all posts

Feb 21, 2008

Validate Input Values With Message List

Private Function ValidateInputValues(ByVal control As Control, ByVal pageType As PageType) As ArrayList
Dim messageList As ArrayList = New ArrayList()
If (pageType <> PageType.Search) Then ' Add/Edit Validation
Dim fullName As TextBox = TryCast(control.FindControl("fullName"), TextBox)
If (fullName IsNot Nothing) Then
If (Not DataFormat.CheckString(fullName.Text)) Then
messageList.Add("Invalid Value (String): fullName")
End If
End If
Dim phoneNumber As TextBox = TryCast(control.FindControl("phoneNumber"), TextBox)
If (phoneNumber IsNot Nothing) Then
If (Not DataFormat.CheckInt32(phoneNumber.Text)) Then
messageList.Add("Invalid Value (Int32): Phone Number")
End If
End If
End If
Return IIf(messageList.Count = 0, Nothing, messageList)
End Function

' Powerful TIPs !
Dim source As WebControl = TryCast(sender, WebControl)

Page Load Function Tips

Get some idea or tips from others work in their page load():

Protected Sub Page_Load(ByVal s As Object, ByVal e As System.EventArgs)

' Registering external javascript file, so that we can have more neater js file management.
Page.ClientScript.RegisterClientScriptInclude("ethan", "ethan.js")

' Cache Setting, I just know about
' ASP Caching can be set manually on the virtual directory property

' Auto-find control and set focus to it;
' I just know got such a syntax, which really near to human language syntax "IsNot"
' and about ClientID property which is very useful in some case.
If (tblpwdDetailsView.FindControl("fullName") IsNot Nothing) Then
Page.Form.DefaultFocus = tblpwdDetailsView.FindControl("fullName").ClientID
End If

' The way they check for QueryString exist or not
If (Not Page.IsPostBack) Then
If (Request.QueryString.Count > 0) Then

Feb 19, 2008

Accessing Web.Config AppSettings Collection Value

Web.config Settings:

** replace ( to < ** replace ) to >

(add key="ContentFrameHeight" value ="600px"/)
(add key="ContentFrameWidth" value="700px"/)
(add key="MenuFrameHeight" value="400px"/)
(add key="MenuFrameWidth" value="250px" /)

Usually AppSettings placement:

Before using System.Configuration.Manager
We might need to add .NET reference, because by default this reference might not be added.
1. Right click "Add reference" > Add the System.Configuration as below figure.

Then you can apply the syntax below:

E.g syntax:
Dim height As String = ConfigurationManager.AppSettings("ContentFrameHeight").ToString

Accesing Master Page With IFRAME Property From Code Behind

Sometimes we need to access code front controls property from code behind, so that we can create a dynamic or configuration variable for this purpose.

How we know what property we have in the code front controls?
In the code front, we can get intellisense helps to verify whether it is a syntax or property with different colors.

ASP.NET Code Front:

(asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server")
(iframe id="mainContent" name="mainContent" src="../Dev.aspx" width="700px"
scrolling="auto" frameborder="0" marginheight="0" marginwidth="0" runat="server"
title="E-Application Content")(/iframe)

** replace ( to < ** replace ) to >

ASP.NET Code Behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
mainContent.Attributes.Add("Height", "700px")
End Sub

IFRAME Code behind having an "Attribute" syntax where we can simply accessing the value of controls in front page. Yet, code front control needed to be "runat=server" mode.

We created a master page, within the master page we have content place holder setup.
Then we create a new page and inherits master page layout.

In this case, we might still need to use traditional html href link to open a page onto a target.
We can use IFRAME with the id and NAME ( name is needed here ) and shown the page on the IFRAME.

With the code above, we can manipulate IFRAME property during page load.