Archive

Archive for the ‘Tricks n Techniques’ Category

How to put banner on dotnetnuke portal?

January 14th, 2006 4 comments

Go to “Admin” > “Site Settings”
Expand the node “Advanced Settings”
Expand the node “Other Settings”
Set the “Banner Advertising” to “Site”

Now go to “Admin” > “Vendor”
Add new “Vendor”
Add “Banner” for the newly added vendor
Remember(/copy) the “Banner Group”

Add “Banner Module” to the page.
Go to the “Banner Options” menu
Put(/paste) the same same “Banner Group” name.
and you are done!!!

Categories: Tricks n Techniques Tags:

MS Access: Pass Variable Value from One Form to Another Form

October 30th, 2005 5 comments

Few days back, I was creating a small prototype for my project using MS Access. It was requiring to pass values to other form. I searched for finding out the way to pass values but couldnt succeed.
The only hint I got is of using Me.OpenArgs argument variable to pass the value across the forms.

To pass value “2″ from a form frmOne to frmTwo, we are using code like

DoCmd.OpenForm "frmTwo", acNormal, , , , acWindowNormal, "2"

In the PageLoad event of the form frmTwo, we can get this value using following code

Dim i as Integeri = CInt(Me.OpenArgs)

Problems with this simple method is we can pass only one value at a time. If we want to pass more values, we must have some kind of delimiter and make a string of all values. but it will require the arguments to be passed in a specific order.

I wrote a small function which will extract the values from the passed value string without requiring the values to be passed in a particular order.

This function requires that we have to pass values in a format like “Var1=Val1:Var2=Val2″. Here each value passed will have a corresponding variable name and Variable name/Value pair will be delimited by “:”. The function will split the argument by the delimiter and extract the value for a particular variable. The code of the function is shown below.

Public Function GetTagFromArg(ByVal OpenArgs As String, ByVal Tag As String) As String
    Dim strArgument() As String
    strArgument = Split(OpenArgs, ":")
    Dim i As Integer
    For i = 0 To UBound(strArgument)
     If InStr(strArgument(i), Tag) And InStr(strArgument(i), "=") > 0 Then
       GetTagFromArg = Mid$(strArgument(i), InStr(strArgument(i), "=") + 1)
       Exit Function
     End If
   Next
   GetTagFromArg = ""
End Function

Now to pass value “2″ from form frmOne to frmTwo we need to write code

DoCmd.OpenForm "frmTwo", acNormal, , , , acWindowNormal, "Count=2"

and in the form frmTwo we can get the value in FormLoad event

Dim i as Integeri = CInt(GetTagFromArg(Me.OpenArgs, "Count" ))

Using this trick, we can pass as many value as possible and the order of the values is not important.

This is extremely simple method struck in my mind at that time. If you have any better solution, please let me know.

Categories: Tricks n Techniques Tags:

Utility for rendering HTMLTable control containing ASP .Net form elements into string

September 24th, 2005 4 comments

Introduction

Many websites have some kind of contact form as shown in the following figure. User fills details and presses the “Send” button. This form takes input from the textbox, checkbox, radiobutton etc, builds string containing html and sends information as HTML email. If the form is expecting many values from user, the developer has to write down big chunk of HTML code in the backend. If the developer has to build more than one such forms, it is really cumbersome. To reduce the precious time of developer, this utility module is developed.

HTML Utility Snap 1

Problem in Direct Rendering of Control

We can use directly Control.Render() method to render html in HTMLTextWriter but with the condition that there should not be any webform controls like TextBox, Label etc. If still we are using this method, it will give error because each server control must be rendered within “form” tag which is having “runat=server” attribute.

Utility Module

Public Function GetHTML(ByVal objControl As Control) As String
	Dim sb As New System.Text.StringBuilder
	GenerateHTML(objControl, sb)
	Return sb.ToString
End Function

This function takes as argument the control object of which we need to get HTML. It will call private method GenerateHTML() which is responsible for generating HTML for the control.

Private Sub GenerateHTML(ByVal objControl As Control, ByVal sb As System.Text.StringBuilder)
	Dim str As New System.Text.StringBuilder
	Dim sw As New System.IO.StringWriter(str)
	Dim hw As New System.Web.UI.HtmlTextWriter(sw)
	If TypeOf (objControl) Is HtmlTable Then
		sb.Append("<table ")
		CType(objControl, HtmlTable).Attributes.Render(hw)
		sb.Append(str.ToString & " >")
		Dim objControl1 As Control
		For Each objControl1 In objControl.Controls
			GenerateHTML(objControl1, sb)
		Next
		sb.Append("</table>")
	ElseIf TypeOf (objControl) Is HtmlTableRow Then
		sb.Append("<tr ")
		CType(objControl, HtmlTableRow).Attributes.Render(hw)
		sb.Append(str.ToString & " >")
		Dim objControl1 As Control
		For Each objControl1 In objControl.Controls
			GenerateHTML(objControl1, sb)
		Next
		sb.Append("</tr>")
	ElseIf TypeOf (objControl) Is HtmlTableCell Then
		sb.Append("<td ")
		CType(objControl, HtmlTableCell).Attributes.Render(hw)
		sb.Append(str.ToString & " >")
		Dim objControl1 As Control
		For Each objControl1 In objControl.Controls
			GenerateHTML(objControl1, sb)
		Next
		sb.Append("</td>")
	ElseIf TypeOf (objControl) Is LiteralControl Then
		sb.Append(CType(objControl, LiteralControl).Text)
	ElseIf TypeOf (objControl) Is TextBox Then
		sb.Append(CType(objControl, TextBox).Text)
	ElseIf TypeOf (objControl) Is Label Then
		sb.Append(CType(objControl, Label).Text)
	ElseIf TypeOf (objControl) Is CheckBox Then
		Dim chk As CheckBox = CType(objControl, CheckBox)
		sb.Append("<input type='checkbox'" & IIf(chk.Checked, "Checked ", " >") & chk.Text)
	ElseIf TypeOf (objControl) Is RadioButton Then
		Dim rad As RadioButton = CType(objControl, RadioButton)
		sb.Append("<input type='radio'" & IIf(rad.Checked, "Checked >", " >") & rad.Text)
	End If
End Sub

This function uses recursion to get each element from control hierarchy. It renders HTML code for the control. Currently it supports, HTMLTable, TextBox, CheckBox, RadioButton, Label, and LiteralControl. As this function uses recursion, the processing may be slower than hardcoding the HTML string. So I wrote other function GetCode() which is responsible for emitting source code for building HTML string. This code you can put in a function and get HTML string of the control. The output of both methods are shown in figure.

HTML Utility Result Snap

Conclusion

If webform is not used very frequently, developer should use, GetHTML() function otherwise they should use use and throw function GetCode(), generate the code, put the code in file and remove this function from solution.

Categories: Tricks n Techniques Tags:

MS Access Link Table Manager

September 23rd, 2005 1 comment

One of our company client was having a powerlink software which is a car junk yard management software. It was running on SQL Server. The client wanted to have some extra reports. They already had one developer who built some reports and then left. Now I had to finish the remaining job. I got SQL Server database as well as half done Access project. Now the problem started.

What that developer did was he used linked tables from the Access to SQL Server. The connection string for all those tables were created by MS Access. When I ported the project on my computer, it crashed because it was not finding that linked table. There were A LOT tables. MS Access provides “Linked Table Manager” but it sucks. It updates link of only one table at a time. This application would eat up my lot of time to change the link. Also, If I would be moving database or the application somewhere else, I would spent again the same amount of time to change the links of tables. I tried to find out any ready made tool for changing these links. I found this article which was showing how to make an application which updates the links of linked table.


Problem with this application was
1) Every time when application starts, it checks wheather the links of table are perfect or not
2) We have to hard code the database name in which linked tables reside
3) I cannot use my own connection string to connect to a particular database.

So inspired by the above mentioned article, I made a custom application which solves these problems. This application requires as input the database in which linked tables reside and the connection string of your choice. Link Table Manager Snap 1

After pressing “Next” You will see a list of all tables. Click on table names for which you want to (more technically, say)refresh the link. After completing the task, it will give feedback.

Link Table Manager Snap 2

Categories: Tricks n Techniques Tags: