Showing posts with label hit. Show all posts
Showing posts with label hit. Show all posts

Monday, March 26, 2012

Newbie ASP.NET Testing probles

OK I'm a complete beginner, and I've hit a snag.
I'm using Dreamweaver to create my ASP.NET pages, and i'm testing on my pc.
I have
XP Pro (Service Pack 2)
.NET Framework 1.1
IIS
and I'm using VB as my language
The problem is when i create my pages (that are stored in the wwwroot folder in inetpub) they do not run the ASP.NET VB code. I do not get errors it just shows some of the text but not the bits that should be generated by the VB and when I view the source code it says exactly what i have typed in my page. Not the HTML page that should be created with ASP.NET VB?, hiding the code you have written.
An example of this is this page.
<%@dotnet.itags.org.Page Language="VB" Debug="True" Explicit="True" %>
<html>
<head>
<title>Date</title>
</head>
<body>
<%
Dim CurrentDate As String
CurrentDate = Today
%>
The Current Date is <%=CurrentDate %>.<br>
</body>
</html>
Which produces the following result
The Current Date is .
My preview page in Dreamweaver says.
The Current Date is {text}.
Has anyone got any ideas please. Do I need to tweak the settings of IIS or do I need to install something into my inetpub?
Any help would be great guys thanks.

I don't use the inline method, which you're trying to use here...but itappears you're missing <script> tags. You should have alook at the tutorials on this site.
http://asp.net/Tutorials/quickstart.aspx

To get into the ASP.NET swing of things, try your page like this:
<%@. Page Language="VB" %>
<script runat="server">
Sub Page_Load (s As Object, e As EventArgs)
lblDate.text = DateTime.Now.ToString("d")
End Sub
</script>
<html>
<head>
<title>Date</title>
</head>
<body>
<form runat="server">
The Current Date is <asp:Label id="lblDate" runat="server"/>
</form>
</body>
</html>

As Frank said, definitely work through the tutorials, and strongly consider picking up a copy ofASP.NET Unleashed, Second Edition. Make that, DEFINITELY pick up a copy of that book! Every new ASP.NET developer should have it.

Cheers Tmorton
I've bought ASP.NET unleashed, Second Edition. Excellent recommendation.
I've got the code to work now. I've stopped using dreamweaver for testing. I create my site and ASPX pages in dreamweaver then open the file in web matrix to insert my code and test the pages.
To follow on from your previous post.
Having used ASP.NET unleashed and looked at the tutorials on the site; I can't find samples of what I am trying to do. After covering adding the date and calendar sections as ways of adding real time data into pages, which technique would be best to add these to multiple pages with the view to making altering the modification properties easiest to change i.e. font type and color without having to change every page on the site?
Should I use Global.asax or the config file in the bin? Or is there another way.
Sorry for the long winded description but I am new to this so I need to explain what I am trying to do.
Any links or tutorial references will be great
Cheers
RDG01


RDG01 wrote:

I've bought ASP.NET unleashed, Second Edition. Excellent recommendation.



Yes, that book is highly recommended across the board. I am glad you are finding it helpful.


RDG01 wrote:


After covering addingthe date and calendar sections as ways of adding real time data intopages, which technique would be best to add these to multiple pageswith the view to making altering the modification properties easiest tochange i.e. font type and color without having to change every page onthe site?


This sounds like a job for a user control. Check out chapter 5 ofthe ASP.NET Unleashed book you have in your hands - Creating CustomControls with User Controls.


Newbie datagrid woes

Data grid

Hi Guys, I am fairly new to .net but have found a lot of the stuff I am attempting is working out as expected. I have however hit a snag with an updateable datagrid. I have spent the last two days searching forums and google for an answer but nothing I do seems to work.
My db is SQL 2000 with 3 columns movieID (Int, Pri) movieTitle(Varchar) movieCategory(int,4 used as a relation to categories table)

Any advice offered will be gratefully received as I am totally at my wits end

The error occurs on datagrid update and I get the following error

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:

Line 104: Dim CategoryID As String = CType(e.Item.FindControl("movieCategory"), DropDownList).SelectedItem.Value
Line 105:
Line 106: Dim MovieTitle As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Line 108:

I am using vs.net 2003 my code is below

Update function


Public Sub OnUpdate(ByVal source As Object, ByVal e As DataGridCommandEventArgs)
Dim CategoryID As String = CType(e.Item.FindControl("movieCategory"), DropDownList).SelectedItem.Value

Dim MovieTitle As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text

' form the update statement
Dim cmd As String = "Update tblMovies set MovieTitle = " & MovieTitle & "MovieCategory = " & CategoryID & "where movieID = " & DataGrid1.DataKeys(e.Item.ItemIndex)

' connect to database
Dim connectionString As String = Global.dbConnect

Dim connection As New SqlConnection(connectionString)
connection.Open()

' call the update and rebind the datagrid
Dim command As New SqlCommand
command.CommandText = cmd
command.Connection = connection
command.ExecuteNonQuery()

DataGrid1.EditItemIndex = -1
BindGrid()
End Sub


Datagrid tag

<asp:DataGrid
id="DataGrid1"
runat="server"
AutoGenerateColumns="False"
CellPadding="5"
HeaderStyle-BackColor="PapayaWhip"
BorderWidth="5px"
BorderColor="#000099"
AlternatingItemStyle-BackColor="LightGrey"
HeaderStyle-Font-Bold="True"
EditItemStyle-BackColor="Yellow"
EditItemStyle-ForeColor="Black"
DataKeyField ="movieID"
OnEditCommand="OnEdit"
OnCancelCommand="OnCancel"
OnUpdateCommand="OnUpdate">
<Columns
<asp:BoundColumn DataField="MovieID" HeaderText="ID" ReadOnly="True" />
<asp:TemplateColumn HeaderText="Movie">
<ItemTemplate>
<asp:Label
Text='<%# Convert.ToString(DataBinder.Eval(Container.DataItem,"MovieTitle")) %>'
Runat="server" ID="lblProduct"/>
</ItemTemplate
<EditItemTemplate>
<asp:TextBox ID="MovieTitle" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"MovieTitle") %>'/>
</EditItemTemplate
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Category">
<ItemTemplate>
<asp:Label
Text='<%# Convert.ToString(DataBinder.Eval(Container.DataItem,"MovieCategory")) %>'
Runat="server" ID="Label1"/>
</ItemTemplate
<EditItemTemplate>
<asp:DropDownList
Runat="server"
ID="movieCategory"
DataSource='<%# GetValues("Category") %>'
DataTextField ="MovieCategory"
DataValueField ="id"
Width ="200" />
</EditItemTemplate
</asp:TemplateColumn
<asp:EditCommandColumn
EditText="Edit"
CancelText="Cancel"
UpdateText="Save" /
</Columns>
</asp:DataGrid>
You cannot directly cast a objects like that into a string object - try something like this:

Dim CategoryID As String
Dim MovieCategoryDDL as dropdownlist
MovieCategoryDDL = e.item.findcontrol("moviecategory")
CategoryID = MovieCategoryDDL.selecteditem.value

Dim MovieTitle As String
Dim myTextBox as textbox
myTextBox = e.item.findcontrol("MovieTitle")
MovieTitle = myTextBox.text