Monday, December 25, 2006

ASP.NET AJAX Tabbed Dialog

For this Tabbed Dialog, you are going to need a MultiView, 2 View and 2 LinkButton. Of course, you can add more controls. I 'm planning to make a templated control so I would like to receive comments.

I read these articles before:
HTML Tabbed Dialog Widget
Web Parts - How to create a tabbed view

The templates
<asp:scriptmanager id="sm1" runat="server">
</asp:scriptmanager>

<asp:UpdatePanel id="up1" runat="server">
<contenttemplate>
<div class="tabs">
<asp:LinkButton
id="tab0" runat="server" CommandArgument="0" CssClass="tabheader"
OnCommand="SearchTab_Command">Basic Search</asp:LinkButton><asp:LinkButton
id="tab1" runat="server" CommandArgument="1" CssClass="tabheader"
OnCommand="SearchTab_Command">Advanced Search</asp:LinkButton>
</div>
<div class="tabcontent">
<asp:MultiView id="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<div class="tabbody">
<asp:Label ID="Label1" runat="server" Text="Tab 1"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Post 1" />
</div>
</asp:View>
<asp:View ID="View2" runat="server">
<div class="tabbody">
<asp:Label ID="Label2" runat="server" Text="Tab 2"></asp:Label>
<br />
<asp:Button ID="Button2" runat="server" Text="Post 2" />
</div>
</asp:View>
</asp:MultiView>
</div>
</contenttemplate>
</asp:UpdatePanel>

The code
<script runat="server" type="text/VB">
Private Sub SwitchCss(ByVal wctl As WebControl)
Dim cc As String = IIf(wctl.CssClass.Equals("tabheader"), "tabheader_active", "tabheader")
wctl.CssClass = cc
End Sub

Protected Sub SearchTab_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
Dim ctl As WebControl

ctl = CType(up1.FindControl(String.Format("tab{0}", MultiView1.ActiveViewIndex.ToString())), WebControl)
SwitchCss(ctl)

MultiView1.ActiveViewIndex = e.CommandArgument

ctl = CType(sender, WebControl)
SwitchCss(ctl)
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If (Not IsPostBack) Then
SwitchCss(tab0)
End If
End Sub
</script>

The CSS
.tabheader {
background-color: #F5F5F5;
color: #C0C0C0;
border: solid 1px #C0C0C0;
}

.tabheader_active {
background-color: #FFFFFF;
color: #608fc8;
border: solid 1px #C0C0C0;
border-bottom: solid 1px #FFFFFF;
cursor:default;
}

.tabs a {
position: relative; width: auto; display:inline;
padding: 2px 4px 2px 4px;
margin: 0 0 0 5px;
font-size:10pt;
}

.tabs a:hover { text-decoration:underline; }
.tabs a.tabheader { color: #666666; }

.tabcontent {
height: 100%; margin-top:2px;
background-color: white;
border: solid 1px #D3D3D3;
}

.tabbody { height: 100%; margin: 9px 9px 9px 9px; }

Sunday, December 17, 2006

Windows AutoPlay Problem

After I installed Nero, I noticed AutoPlay wouldn't start. What was the problem?. My coworker Ruben gave me a self tip. Greetings Respaq.

Look this article:
Autoplay Repair Wizard

Wednesday, December 13, 2006

Tunning your Code for Performance

When I get a problem about performance issue, The first thing I think are review: loops, comparison and assignments sentences, depending of the kind of project.

In other words:
- Boxing/Unboxing
- Value Types (String, Int, Struct, Class, etc)
- Loops (For each, While, etc)
- Comparison(==, !=, Equals, etc)
- Database Access Topics (DataSet, DataReader, CommandType)
- Exception Handling (Based in Values, Try...Catch)
- Multithreading

I read these articles before:
Effective C# - Performance notes
Performance Tips and Tricks in .NET Applications

Saturday, December 09, 2006

XSLT Templates

If you need to add format for display transformation, you can use XSLT templates.

Numeric Templates
<xsl:template name="currencyValue">
<xsl:param name="Number" />
<xsl:value-of select="format-number($Number,'#,###,##0.00')" />
</xsl:template>

<xsl:template name="integerValue">
<xsl:param name="Number" />
<xsl:value-of select="format-number($Number,'####0')" />
</xsl:template>

For invoke them
...

<xsl:variable name="totalRows" select ="count(reg/amount)" />
<xsl:variable name="totalCustomer" select ="sum(reg/amount)" />
...

<xsl:call-template name="currencyValue">
<xsl:with-param name="Number" select="$totalCustomer" />
</xsl:call-template>
...
<xsl:call-template name="integerValue">
<xsl:with-param name="Number" select="$totalRows" />
</xsl:call-template>
...
The ouput
2,333.01
561

Your Gmail Account as SMTP Server, ASP NET 2.0

It's gorgeous, when you don't lose time to configure SMTP Server for a simple test. You could use your Gmail Account, to do it.

I read this article before:
Configuring other mail clients
Sending Email with System.Net.Mail
How to use System.Net.Mail.SmtpClient via SSL and Authentication?

Well for accomplish that, first adjust your web.config...

<system.net>
<mailsettings>
<smtp>
<network host="smtp.gmail.com" port="587" username="youraccount@gmail.com" password="yourpassword" defaultcredentials="false">
</network>
</smtp>
</mailsettings>
</system.net>


You write a few lines...

MailMessage message = new MailMessage();

message.From = new MailAddress("sender@domain.com");
message.To.Add(new MailAddress("destination@domain.com"));
message.Subject = "The subject";
message.Body = "The content";

SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Send(message);


And run it.

Tuesday, December 05, 2006

Creating Custom WorkFlow for WSS 3.0

For create custom WorkFlow for WSS, in this case with Visual Studio 2005, you need the download:
Workflow Developer Starter Kit for WSS 3.0

Of course, you need too, WSS 3.0 running on Windows Server 2003.

Initial walkthrough
Creating WSS 3.0 Workflows with Visual Studio 2005

Saturday, December 02, 2006

DNN Custom Module

I recently developed a DNN Custom Module; by the way it doesn't very difficult. It's very explained. Basically, you use an ASCX and invoke a DNN's DAL Libraries for perform the data extraction.

I read this article before:
http://www.adefwebserver.com/DotNetNukeHELP/DNN_Module4/

Open Sources in C#

All open sources as you would imagine in C#. It's like a directory, in addition you could suggest other projects.

http://csharp-source.net/

Any messenger, anywhere

Meebo for Free is an interesting website for instant messaging. You can use Aim, Yahoo Messenger, Gtalk, MSN Messenger and ICQ as one. This was a tip of my coworker Miguel; greetings!

http://www29.meebo.com/index-en.html

Thursday, November 30, 2006

Search Query for Transact SQL

When you try to add Search functionality to a simple WebForm you think, in several parameters as you need. This idea, is an opposite way, a single parameter to perform a search.

Basically, I created 2 Store Procedures:
1. dbo.usp_SearchUsers {SearchData}
2. dbo.usp_DYN_FilterGenerator {TemplateQuery}, {SearchData}

I didn't say that is the best way, but it is an option. I would like to receive comments.


I read these articles before:
http://www.sql-server-performance.com/transact_sql.asp
http://www.sommarskog.se/dyn-search.html

create proc dbo.usp_SearchUsers
(@request nvarchar(1000))
as
SET NOCOUNT ON

-- SearchUsers 'admin'

declare @statement nvarchar(4000)
declare @filterStatement nvarchar(2000)
declare @data nvarchar(1000)

set @data = rTrim(lTrim(@request))

-- the query
set @statement = N'
SELECT a.aiID, a.CIP, b.FirstName, b.LastName, b.Email,
a.Birthdate, a.Address, a.MobilPhone, a.WorkPhone, a.HomePhone
from dbo.Additional_Information a
INNER JOIN dbo.Users b ON a.aiID = b.UserID
WHERE b.IsSuperUser = 0 AND ({0})>0'


-- template where statement
set @filterStatement = N'
patIndex(''{0}%'',b.FirstName) +
patIndex(''{0}%'',b.LastName) +
patIndex(''{0}%'',b.Email)'

exec dbo.usp_DYN_FilterGenerator @filterStatement OUTPUT, @data
set @statement = replace(@statement,'{0}',@filterStatement)

print len(@statement)
print @statement
print 'Finished.'

exec sys.sp_executesql @statement

end -- end of usp_SearchUsers


-- user sp generator
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
create proc [dbo].[usp_DYN_FilterGenerator]
(@filterTemplate NVARCHAR(2000) OUTPUT, @data NVARCHAR(1000))
as
begin

declare @tempData nvarchar(250)
declare @filter nvarchar(2000)
declare @i int
declare @cachedLen int

set @filter = ''
set @cachedLen = len(@data)

while (@cachedLen > 0)
begin

set @i = charIndex(' ', @data)
if (@i=0)
set @i = @cachedLen + 1

set @tempData = left(@data, @i - 1)
set @data = substring(@data,@i + 1,@cachedLen)
set @cachedLen = len(@data)

if len(@filter) > 0
set @filter = @filter + ' + ' -- ADD version

set @filter = @filter + replace(@filterTemplate,'{0}', @tempData)
end
set @filterTemplate = @filter

end -- end of usp_DYN_FilterGenerator
Google