Instead of merely using an ASP.Net Hyperlink control to link to another page, you can mix in the Javascript Window.open method, just like you did in Classic ASP – like this:
<asp:Hyperlink id=”mylink” NavigateURL=”javascript:window.open (‘faqs.html’,'Info’,'width=500,height=400,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes’);” Text=”Click Me” runat=”server” />
(Where ‘faqs.html’ is your own file name)
Category Archives: Tips
System.Data.Comm.DbDataRecord Error
If you are using data from a database table to populate a DropDownList or ListBox, and you get this for each item in the control, to fix it, you MUST assign a datatextfield to the server control equal to the column you want showing in your control.
You can either do this in code, before binding, or in the server control itself.
Select Specific DropDownList Item
With a dropdown list – you can dynamically select items in the list with a sort of ‘built-in’ find routine.
To select a certain item, based on the Value of the item in the list:
DropDownList.SelectedIndex = DropDownList.Items.IndexOf(DropDownList.Items.FindByValue(YourValueHere))
To select a certain item, based on the Text of the item in the list:
DropDownList.SelectedIndex = DropDownList.Items.IndexOf(DropDownList.Items.FindByText(“YourTextHere”))
OR – you can do it this way:
DropDownList.Items.FindByText(“TextYouAreLookingFor”).Selected = true
or, using the value of the item
DropDownList.Items.FindByValue(“ValueYouAreLookingFor”).Selected = true
Dynamic Sizing of ASP.Net Textbox
This tip uses the Northwind Database Employee table columns. First – create a connection and a DataReader…
Then, add lines similar to the following, creating variable names for returned items to match your particular sql statement:
While objDR.Read() strFirst=Trim(objDR("Firstname")) strLast=Trim(objDR("LastName")) strTitle=Trim(objDR("Title"))End While
Here’s the function that does the actual work:
Function doLen(item as string) Dim intWdth as int32 intWdth=item.Length * 7 doLen = Unit.point(intWdth)End Function
(to get better spacing so the ‘*7′ part of the function works better, I optionally added a CSSClass which forces the textbox font to Courier)
Then, inside the ASP.Net TextBox server control, for each one, include the following:
Width=”<%# doLen(varName)%>”
Thanks to DataGridGirl for collaboration on this one.
ASP.Net Server Controls Not Showing on pages
It’s possible that ASP.Net is not registered correctly on your system.
Try running aspnet_regiis from the command prompt.
Here’s the default location:
C:\WINNT\Microsoft.NET\Framework\<<ASP.Net Version#>>\aspnet_regiis.exe -i
Windows Server 2003, you must use aspnet_regiis -i -enable
This is because of the “Web Service Extensions” feature in IIS 6
(if you install VS.NET or the framework without IIS installed, and then go back in and install IIS afterwards, you have to re-register so that ASP.NET ‘hooks’ into IIS properly.”
Add Item to Bound DropDownList
To add an item to the top of a DropDownList at any time, here’s the code:
MyDDL.items.insert(0,”WhateverYouWantHERE”)
The ’0′ shows that it needs to insert the item at the top position of the DropDownList item collection. The second part, “WhateverYouWantHERE” is the actual text you want displayed. You could also use this to put a blank item at the top:
MyDDL.items.insert(0,”")
or to specify both value and text:
Dim liItem as ListItem=New ListItem(“text”, “value”)
MyDDL.Items.Insert(0, liItem)
Check DB to see if Records exist
When inserting a record into the database, it’s always better if it’s not entered a second time by an unsteady index finger.
To make sure this doesn’t happen – with the existing data, query the database first to see if it exists, then, if it doesn’t exist, then go ahead and enter the information.
Two Fields in a DropDownList
Unfortunately, the dropdownlist datatextfield only accepts one fieldname as a parameter, when accessing a database to fill the dropdownlist. To get around this, if you need, say, a first name AND a last name to appear, is to take care of this in the SQL statement a little something like this:
“Select FirstName + ‘ ‘ + LastName as fullname from Employees”
then use ‘fullname’ as the datatextfield for the dropdownlist
Make a Horizontal Rule Visible or Invisible
If you want to refer to a Horizontal rule in coding, to make it visible or invisible, just use the runat=Server designation, along with an ID and you’re ready to go:
<hr id=”rule” visible=”true” runat=”server”/>
Setup Check List
When installing ASP.Net, the Framework, or for that matter, any new app, here are some things you need to check first, just to make sure you get a good installation:
1. Temporarily disable virus protection
2. Remove All Temp Files
3. Make sure no other app is running
4. Run chkdsk/scandisk/Norton’s WinDoctor, or some other fix-it app against your HD to make sure it’s in the best shape it can be.
5. THEN – try installing