asp.net tab index

Leave a comment

here’s a quick one. I created a web page with 2 textboxes, called them textbox1 and textbox2. The problem was that when i tabbed from the first one to the second one it would jump somewhere else on the page. I’ve created pages in the past, but it always just worked correctly in all browsers. It could have been because I added textbox2 after, but I’ve inserted controls in between 2 controls and the tab index has worked automatically. I went about and set the tabindex property of the control to 0 and 1 respectively. It still didn’t work. So after getting frustrated i tried setting them to 1 and 2 (instead of 0 and 1) and it worked perfectly. Hope this helps someone out.

Advertisements

Deploying An Asp.Net Site To Network Solutions With Membership

13 Comments

Tools Used:

Visual Studio 2008 Professional Edition

SQL Server Management Studio

Recently I was developing an ASP.NET site which worked fine on my computer, but when I went to deploy it to Network Solutions, it did not work, and their Support was not very helpful.  They told me  that membership could not be used. They also told me that asp.net, while supported, could not be used on the server since it is shared hosting environment.  Further they told me that they could not create an “Application” like I would using IIS also because it is a shared hosting environment.  They also do not have an option (in windows) for VPS that would allow full control.  All the stuff they told me  is basically not true or only partially true.

First off in order to get your asp.net site up and running (without membership) all you have to do is copy your aspx files to the root of the htdocs folder that they supply for you.  This in itself is an application directory and because of this you can run ASP.NET pages.

Second, you can use membership by going to their admin pages, creating a database, exporting your data and schema from your current membership database, and then running a script in query analyzer. Here’s how you do this:

1.       To start off you should have a site with membership that allows you to login successfully from your local computer. There are plenty of tutorials online that will help you out with this but it’s beyond the scope of this post.

2.       Now we create the sql database on Network Solutions.  Go to Manage Account>>My Hosting Packages>>Click on Web Hosting Toolkit>>Go down to the bottom of the page and click Database Manager >>Click Microsoft SQL Server (Note: if nothing pops up and you get “sessionId=0”, logout using the link on the top right hand side of the page.)

3.       Click Add to add a new DB . Then enter your information for the new database.  Just make a note of what you entered here:

4.       Now that we have a DB, lets connect to it using SQL Server Management Studio.  Network Solutions gives you the address to which to connect to after you create the database.  When you are in database manager , select your newly created database and then click edit to view it. Open SQL Server Management Studio and enter the ip address, your username and password to connect.

5.       Now that you are connected, minimize SQL Management Studio, and then open up your website in Visual Studio. We will now we will create the .SQL script to recreate the schema and data on the network solutions database we created above.

6.        In Server Explorer, Right Click on aspnetdb.mdf and click “Publish To Provider”, then follow the wizard. This will create a sql script replicating the aspnetdb.mdf database. here’s what my screen looked like.

7.       Now that you have the sql script created, open it using your favorite text editor, and then copy all of it’s contents.

8.       Go back to SQL Management Studio, Find your database name under databases and (you can see all network solutions databases hosted on that shared server), single click it and then click “New Query”.  This will open up a sql window.

9.       Paste all the code that you copied in step 7, and execute the script.  This should recreate all your user information, roles, security, etc.  I did not have any errors when doing this so I can’t really help you out if it doesn’t work.

10.   Next modify your web.config file to include a new connection string to point to this new database. Here’s the string that I used in my web.config file.


<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=IPAddress;Initial Catalog=URDBName;User Id=URUsername;Password=***********;" providerName="System.Data.SqlClient" />
</connectionStrings>

11.   Next ftp all of your files up to Network Solutions server using the Manage Account>>FTP/ContentPublishing  provided by them.  I use filezilla, it’s easier.  I uploaded them to the root of the htdocs folder, and voila everything worked.

Another note, Network Solutions support was telling me that If I have an access database (which I do), I need create a new folder called “db” under the HTDocs folder and adjust my code to point to this folder.  They said this is due to permissions. This worked flawlessly.

Another note: If you use smtp in your asp.net, create your email address in network solutions Manage Account, and then add the following information to your web.config file:

<system.net>
<mailSettings>
<smtp from="myemailaddress@mydomain.com">
<network
host="localhost"
port="25"
userName="myemailaddress@mydomain.com"
password="*********" />
</smtp>
</mailSettings>
</system.net>

I would also like to give credit to this site for information on the Visual Studio schema export.

ASP.NET Accessing SQL Data From Codebehind Without A Control

Leave a comment

I needed to access a SQL 2008 database from my codebehind without a control like a gridview.  After scouring the internet I put together the pieces to do so.

If you were familiar with the (oldschool) “non .NET”  scripting you remember doing something like the following:

Conn = Server.CreateObject("ADODB.Connection") 
Conn.Open("ODBC-DSN", "sa", "**********") 
rs = Server.CreateObject("ADODB.Recordset") 
rs.Open(StrSQL, Conn) 
Do While Not rs.eof 
Urvariable=rs("whs-num").value 
rs.movenext() 
Loop

You can still do this in an ASPX page if you use aspcompat=”true”, but as many women have said to me throughout the years “It’s time we move on Vin” (or “no, it really IS you” but that doesn’t apply here)   So the replacement .NET code to do the same thing is…

Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Data.SqlTypes
Dim URConnection As System.Data.SqlClient.SqlConnection
Dim URCommand As System.Data.SqlClient.SqlCommand
Dim URDataReader As System.Data.SqlClient.SqlDataReader
Dim StrSQL, URVariable as String
'Your sql string
strSQL = "Select * From Sales"
'Set your Connections and your command
URConnection = New System.Data.SqlClient.SqlConnection("server=URSERVER; initial catalog=URDB;uid=sa;pwd=********")
URConnection.Open()
URCommand = New System.Data.SqlClient.SqlCommand
URCommand.Connection = URConnection
URCommand.CommandText = StrSQL
URDataReader = URCommand.ExecuteReader()

While (URDataReader.Read)
URVariable = URDataReader.Item("whs-num")
End While

URDataReader.Close()
URDataReader = Nothing
URCommand = Nothing
URConnection.Close()
URConnection = Nothing

If you want an explanation of the newer commands, you can Google  it or look on MS’s site.  For my purposes of creating a data driven web page every once in a while, the nitty gritty is not what I’m concerned about.  I just need it to work.  If you have an aspx page that uses old asp code now, it actually is not too difficult to convert it over using a few copy and pastes and Find and Replaces.

asp.net error BC30456

Leave a comment

I was building a website using Visual Studio 2008 and everything would build fine. It also published with no problems, however I kept on getting errors when visiting some of the pages. I ended up finding the answer on an old message post that saved me a lot of headaches. The guy who posted it didn’t write English very well, so I’ll give a more detailed example and explain how the fix worked for me.

This may happen when you make a copy of a page and then leave the class the same as the page that you originally copied. Heres more detail:

The error message i was getting:

BC30456: ‘Title’ is not a member of ‘ASP…

BC30456: ‘InitializeCulture’ is not a member of ‘ASP…

This might occur if the “inherits” at the top of your ASPX page doesn’t match your codebehind class. so for instance, I had a page called TermsCodeLookup.aspx, and I needed to modify it a bit for someone, so instead of recreating it, I copied the codebehind to a new page using the name  TermsCodeLookupNew.aspx:

in my TermsCodeLookupNew.aspx page:

<%@ Page Language=”VB” MasterPageFile=”~/master1.master” AutoEventWireup=”false” CodeFile=”TermsCodeLookupNew.aspx.vb” Inherits=”MemberPages_AR_TermsCodeLookup” title=”Untitled Page” %>

and in my TermsCodeLookupNew.aspx.vb code I had:

Partial Class MemberPages_AR_TermsCodeLookup
Inherits System.Web.UI.Page

If you look at the code above in the aspx file, I still had inherits= pointing to the original termscodelookup.aspx page that i had created instead of the TermsCodeLookupNew.aspx page.   And in the codebehind .vb file the partial class was named after the old termscodelookup page instead of termscodelookupnew.

it was an easy fix by just modifying the two like so:

<%@ Page Language=”VB” MasterPageFile=”~/master1.master” AutoEventWireup=”false” CodeFile=”TermsCodeLookupNew.aspx.vb” Inherits=”MemberPages_AR_TermsCodeLookupNew” title=”Untitled Page” %>

Partial Class MemberPages_AR_TermsCodeLookupNew
Inherits System.Web.UI.Page

Hope this helps someone like it did for me.  I’ll give props to the original poster and website here.  another way to fix this is to uncheck the box “Allow this precompiled site to be updateable”

UPDATE: Another area where this can occur is when you get this error and everything looks correct  in your pages and the inherits matches the codebehind class.  The reason this may not work is that the class name may reside in another webpage that you may have copied, and forgot about or never used to begin with.  Just do a solution-wide search  in visual studio of the class name of the page that you are getting the error on. Chances are it will find it in some long-forgotten page, or maybe a copy you made of a page in which you wanted to keep the original just in case.

Partial Class MemberPages_AR_TermsCodeLookup
Inherits System.Web.UI.Page

Dropdownlist Tooltips

Leave a comment

Today i was writing a program, and I ran into a problem where I had DropDownLists drawing data from the database, but the text was really long, thus making the DDL’s stretch halfway accross the page.  After doing a little searching I was able to simply solve it by adding a little code.

Basically what this does is:  in the pre_render section of the dropdownlist control, you

1. Add the “title” attribute to each list item (regardless of size), this way they all have tooltips

2. Scroll through the list items to see how many characters we have

3. If they’re greater than 95, grab the left 95 characters of text, add an elipses

Protected Sub ddlProgramSession6_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlProgramSession6.PreRender

For Each li In ddlProgramSession6.Items

li.Attributes.Add(“title”, li.Text)
If li.Text.Length > 95 Then
Dim strTemp As String
strTemp = Left(li.Text, 95) & “…”
li.Text = strTemp
End If

Next
End Sub

This was an easy way to solve this problem.  Maybe in the future I’ll try to make the elipses into a hyperlink so it’s more intuitive to the user that there is more text.