Thursday, July 29, 2010

designer.vb does not save changes to Partial Public Class

Delete the designer.vb page, right click on the aspx page and choose Convert to Web Application.

Friday, July 9, 2010

Formatting a phone number in ASP.NET


<asp:Label ID="Label1" runat="server" Text='<%# String.Format("{0:(###) ###-####}", Convert.ToInt64(DataBinder.Eval(Container.DataItem,"PhoneNo"))) %>'></asp:Label>

Tuesday, June 29, 2010

Duplicate GridView Row from ItemTemplate

Example:

<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:ImageButton ID="CopyButton" runat="server" OnClick="CopyButton_Click" AlternateText="Duplicate" ImageUrl="../Images/Copy.png" CausesValidation="False" />
</ItemTemplate>
</asp:TemplateField>

Now put this in your code behind:

Protected Sub CopyButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim row As GridViewRow = CType(CType(sender, ImageButton).NamingContainer, GridViewRow)
Dim strValue As String = GridView1.DataKeys(row.RowIndex).Value.ToString()
Dim CopyCommand As String = "INSERT INTO [TableName] ([Column1], [Column2], [Column3]) SELECT [Column1], [Column2], [Column3] FROM [TableName] WHERE [ID] = " & strValue
Try
SQLDataSource1.InsertCommand = CopyCommand
SQLDataSource1.Insert()
Catch ex As Exception
End Try
End Sub

Monday, June 28, 2010

designer.vb does not recognize AjaxControlToolkit

You need to reference the AjaxControlToolkit in Visual Web Developer 2010 Express.

Go to Project > Add Reference...

Click the Browse tab and select your AjaxControlToolkit.dll

Click OK

Friday, June 25, 2010

Multi-Targeting using Visual Web Developer 2010 Express

Click New Project... from the Start Page

Name your New Project and click OK

Click the Project menu and select [Your Project] Properties...

Select the Compile properties and click Advanced Compile Options...

Select your framework from the Target Framework menu and click OK

Friday, June 18, 2010

Alternative to Eval and an IF statement

The objective here was to show or hide a label depending on whether or not it has data. In Classic ASP we would've wrapped an if statement around it, but in ASP.NET we can set the visibility to True or False as demonstrated below.

Example:

<asp:Label ID="Label1" runat="server" Text='<%# Eval("ID")%>' Visible='<%# Eval("ID") > 0 %>'>

Wednesday, June 16, 2010

Link to an AJAX Tab on a different page

You can use a HyperLink control to open any tab you specify by setting the tab controls ActiveTabIndex.

Example:

Test

Now put this in your code behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
TabContainer1.ActiveTabIndex = Request.QueryString("TabID")
Catch ex As Exception
TabContainer1.ActiveTabIndex = "0"
End Try
End Sub