Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Wednesday, April 16, 2014

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
Author: Steve Gray Created: 4/11/2009 8:00 PM RssIcon
Code samples and tips from the fine folks in the DevShed. As always, we welcome your comments!
By Steve Gray on 12/18/2012 9:36 AM

It’s cool to have the ‘Login’ button on an asp:Login control be the default button on the page, so that it responds to the ‘Enter’ key. I find that a percentage of website users on a website will complain about not being able to log in because they’re hitting ‘Enter’, and not the ‘Login’ button.

Partial Class Account_Login
    Inherits AppInherit
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim loginButton As Button = DirectCast(Me.LoginUser.FindControl("LoginButton"), Button)
        Me.Master.Page.Form.DefaultButton = loginButton.UniqueID
    End Sub
End Class
(sigh)

So, this code will do it. In this example the login page is inside a master control.

By Steve Gray on 12/16/2012 4:02 PM

This section of code will allow you to ban IP addresses in IIS 7.

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim ipSecuritySection As ConfigurationSection = config.GetSection("system.webServer/security/ipSecurity", "Default Web Site")
      Dim ipSecurityCollection As ConfigurationElementCollection = ipSecuritySection.GetCollection

      Dim addElement As ConfigurationElement = ipSecurityCollection.CreateElement("add")
      addElement("ipAddress") = "192.168.100.1"
      addElement("allowed") = False
      ipSecurityCollection.Add(addElement)

      Dim addElement1 As ConfigurationElement = ipSecurityCollection.CreateElement("add")
      addElement1("ipAddress") = "169.254.0.0"
      addElement1("subnetMask") = "255.255.0.0"
      addElement1("allowed") = False
      ipSecurityCollection.Add(addElement1)

      serverManager.CommitChanges()
   End Sub

End Module

By Steve Gray on 8/20/2012 11:01 AM

I migrated TFS from one server to another, and I’m getting this error.

I solved it by opening the VS command line tool and typing in TF workspace PROBLEM_WORKSPACE_NAME, that opened up a dialog that let me edit the workspaces.

By Steve Gray on 6/5/2012 7:15 PM

 

  1. Dim strSopnumber As String = ""
  2.  
  3. For Each rowInfo As GridViewRowInfo In RadGridView1.Rows
  4.     strSopnumber = rowInfo.Cells("sopnumbe").Value
  5. Next
By Steve Gray on 5/29/2012 12:30 PM

This is code that will show you how to code the Telerik RadComboBox. This code makes use of the Enable Load On Demand functionality

 

 

  1.   <%@ Page Language="VB"AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>
  2. <%@ Register Assembly="ComponentArt.Web.UI" Namespace="ComponentArt.Web.UI" TagPrefix="ComponentArt" %>
  3.  
  4.  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6.  
  7. <html xmlns="http://www.w3.org/1999/xhtml" >
  8. <head >
  9.     <title></title>
  10. </head>
  11. <body>
  12.     <form id="form1" runat="server">
  13.     <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
  14.  
  15.     <telerik:RadComboBox ID="cboITEMNMBR" runat="server"></telerik:RadComboBox>
  16. </form>
  17. </body>
  18. </html>

 

  1. Imports dynData
  2. Partial Class test
  3.     Inherits InheritedPage
  4.  
  5.     Protected Sub cboITEMNMBR_ItemsRequested(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles cboITEMNMBR.ItemsRequested
  6.  
  7.         'load on demand = server side manual
  8.         Dim strItemNumber As String = e.Text.Trim
  9.         Me.cboITEMNMBR.DataSource = SPs.FP_IV00101_SEL5(strItemNumber, AppUser.strLastDB).getTable
  10.         Me.cboITEMNMBR.DataBind()
  11.  
  12.     End Sub
  13.  
  14.     Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
  15.  
  16.     End Sub
  17.  
  18.  
  19.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  20.         If Not IsPostBack Then
  21.  
  22.             Me.cboITEMNMBR.DataSource = SPs.FP_IV00101_SEL5("", "ngb01").getTable
  23.             Me.cboITEMNMBR.Width = 400
  24.             Me.cboITEMNMBR.DataValueField = "itemnmbr"
  25.             Me.cboITEMNMBR.DataTextField = "itemdesc"
  26.             Me.cboITEMNMBR.DataBind()
  27.             Me.cboITEMNMBR.EmptyMessage = "Choose an item"
  28.             Me.cboITEMNMBR.HighlightTemplatedItems = True
  29.             Me.cboITEMNMBR.Filter = Telerik.Web.UI.RadComboBoxFilter.StartsWith
  30.  
  31.             'Load On Demand - server side manual
  32.             Me.cboITEMNMBR.EnableLoadOnDemand = True
  33.             Me.cboITEMNMBR.ShowMoreResultsBox = False
  34.             Me.cboITEMNMBR.EnableVirtualScrolling = False
  35.             Me.cboITEMNMBR.ItemsPerRequest = 25
  36.  
  37.         End If
  38.  
  39.     End Sub
  40. End Class
By Steve Gray on 7/6/2011 1:58 PM

I’ve placed some controls onto a page dynamically, and was having trouble accessing them in the code behind. There were several complications – they were inside a place holder, inside a master page. Not my favorite technique, but business needs dictated it.

After a while I stumbled across the code to make it work, and I wanted to record it.

HTML:

  1. <%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="WebForm2.aspx.vb" Inherits="WebApplication1.WebForm2" %>
  2. <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
  3. </asp:Content>
  4. <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  5. <div>
  6.         <asp:PlaceHolder ID="Placeholder1" runat="server"></asp:PlaceHolder><br />
  7.         <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
  8. </div>
  9. </asp:Content>

and the code behind:

  1. Public Class WebForm2
  2.     Inherits System.Web.UI.Page
  3.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  4.  
  5.         'add a textbox directly to the Placeholder
  6.         Dim tb As New TextBox
  7.         tb.ID = "txtTemp"
  8.         Me.Placeholder1.Controls.Add(tb)
  9.  
  10.  
  11.         'add a text box that is nested inside a table
  12.         Dim t As New HtmlTable
  13.         Dim r As New HtmlTableRow
  14.         Dim c As New HtmlTableCell
  15.  
  16.         tb = New TextBox
  17.         tb.ID = "txtTemp2"
  18.         c.Controls.Add(tb)
  19.         r.Controls.Add(c)
  20.         t.Controls.Add(r)
  21.         Placeholder1.Controls.Add(t)
  22.  
  23.  
  24.     End Sub
  25.  
  26.     Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
  27.         'this works for the first textbox
  28.         Dim tb As New TextBox
  29.         tb = Me.FindControl("ctl00$ContentPlaceHolder1$txtTemp")
  30.  
  31.         'and this works for the textbox inside the table. Note the ',0'
  32.         Dim tb2 As New TextBox
  33.         tb2 = Me.FindControl("ctl00$ContentPlaceHolder1$txtTemp2", 0)
  34.  
  35.     End Sub
  36. End Class
By Steve Gray on 7/1/2011 11:25 AM

John Adams had written to his wife Abigail during the debate of the Declaration of Independence:

"The second day of July, 1776, will be the most memorable epoch in the history of America. I am apt to believe that it will be celebrated by succeeding generations as the great anniversary festival. It ought to be commemorated as the day of deliverance, by solemn acts of devotion to God Almighty. It ought to be solemnized with pomp and parade, with shows, games, sports, guns, bells, bonfires, and illuminations, from one end of this continent to the other, from this time forward forever more"

By Steve Gray on 7/1/2011 10:27 AM

Recently I was trying to troubleshoot an MSIEXEC install (you know, where you see MyInstallName.msi in the folder) that wasn’t really giving an error message, and wasn’t logging anything either.

I stumbled upon KB314852 that details how to get the MSIEXEC app to use verbose logging. It applies to XP, but worked fine in Server 2008

http://support.microsoft.com/kb/314852

Enable Windows Installer Logging by Adding Registry Entries
Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:
322756  (http://support.microsoft.com/kb/322756/ ) How to back up and restore the registry in Windows

Start Registry Editor (Regedt32.exe), and then create the following path and keys in the registry:
HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Installer

Reg_SZ: Logging
Value: voicewarmup

The letters in the value field are the options that are available to use with Windows Installer logging. You can use the options in any order. Each option turns on a specific logging mode. For MSI version 1.1, the function of each option is as follows :
v - Verbose output
o - Out-of-disk-space messages
i - Status messages
c - Initial UI parameters
e - All error messages
w - Non-fatal warnings
a - Start up of actions
r - Action-specific records
m - Out-of-memory or fatal exit information
u - User requests
p - Terminal properties
+ - Append to existing file
! - Flush each line to the log

* - Wildcard, to log all information except for the v option. To include the v option, specify *v.
It is recommended that you use this service only for troubleshooting. Leaving the service turned on creates a new Msi*.log file every time you use the Add/Remove Programs tool in Control Panel. This activity adversely affects system performance and disk space.

By Steve Gray on 7/1/2011 7:55 AM

This works in SQL 2008 and doesn’t in SQL 2000, not sure about 2005

We all have to work with ‘black box’ applications sometime – the kind that has a database with tables and stored procedures that you can’t see into but you still have to work with it.

I had a case like that today, the parameters that I was sending to an encrypted stored procedure were not matching up. Usually that’s a versioning issue. Here’s a handy piece of code that will show you all the parameters in a stored procedure

  1. select PARAMETER_NAME, PARAMETER_MODE, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION, NUMERIC_SCALE
  2.     from INFORMATION_SCHEMA.PARAMETERS
  3.     where SPECIFIC_NAME = 'taUpdateCreateCustomerRcd'
  4.     order by ORDINAL_POSITION
SQL
By Steve Gray on 6/20/2011 9:04 AM

I’m writing a new web site (which I hope to announce soon) and I need to use a dynamic where clause. The user is going to enter some filter conditions on the web site and the data that they see will be filtered by that criteria. I’m using the RadFilter control by Telerik; it basically gives me the complete where clause.

So, I have a something like

Select * from myTable Where @WhereClause

Of course, that’s not valid SQL. What to do? In the end, I’ll have to use my least favorite solution, dynamic SQL using the EXEC command. I’ll change the statement above into

DECLARE @sql varchar(1000)

SET @sql = ‘SELECT * FROM myTable WHERE ‘ + @WhereClause

exec(@sql)

Ug. At anyrate, the best advice that I could find on the subject was here: http://sommarskog.se/dyn-search.html, I didn’t want to lose the reference so I’ll blog it.

SQL
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us