i am using vs.net 2003. I have do the delete function in the datagrid. Bu the problem is when i run in IE, the "Error on page" msg will occur the the bottom of IE when i click "delete". Please help me....

below is my is the print screen for the error:

http://www.2and2.net/files/45eee0ef8c577.jpg

Below is my coding:
aspx:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="AdminAddComment.aspx.vb" Inherits="Ebook.AdminAddComment"%>
<%@ Register TagPrefix="ASPNETE_BOOK" TagName="header" src="header.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Admin Add Comment</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="[URL]http://schemas.microsoft.com/intellisense/ie5[/URL]" name="vs_targetSchema">
</HEAD>
<body>
<ASPNETE_BOOK:HEADER id="header" runat="server" NAME="header"></ASPNETE_BOOK:HEADER>
<table cellSpacing="0" cellPadding="0" width="805" bgColor="#f2eef5" border="1">
<TBODY>
<tr>
</tr>
<tr>
<td>
<form id="viewAns" method="post" runat="server">
<TABLE cellSpacing="0" cellPadding="8" width="805" bgColor="#f2eef5" border="0">
<TR>
<TD width="805" height="15"><FONT size="3">
<P><FONT size="3"><asp:imagebutton id="ImageButton1" runat="server" ImageUrl="[URL]file:///C:\Inetpub\wwwroot\ebook\Pic\Home1.gif[/URL]"
Width="96px"></asp:imagebutton>
<asp:HyperLink id="HyperLink3" runat="server" ImageUrl="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\editprofile1.gif">HyperLink</asp:HyperLink">file:///C:\Inetpub\wwwroot\ebook\Pic\editprofile1.gif">HyperLink</asp:HyperLink>
<asp:HyperLink id="HyperLink4" runat="server" ImageUrl="[URL]file:///C:\Inetpub\wwwroot\ebook\Pic\searchbook1.gif[/URL]"
NavigateUrl="SearchBook.aspx">HyperLink</asp:HyperLink>
<asp:HyperLink id="HyperLink5" runat="server" ImageUrl="[URL]file:///C:\Inetpub\wwwroot\ebook\Pic\viewnotice1.gif[/URL]"
NavigateUrl="ViewNotice.aspx">HyperLink</asp:HyperLink>
<asp:HyperLink id="HyperLink6" runat="server" ImageUrl="[URL]file:///C:\Inetpub\wwwroot\ebook\Pic\deletebook1.gif[/URL]"
NavigateUrl="DeleteBook.aspx">HyperLink</asp:HyperLink>
<asp:ImageButton id="ImageButton2" runat="server" ImageUrl="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\authoring.gif"></asp:ImageButton">file:///C:\Inetpub\wwwroot\ebook\Pic\authoring.gif"></asp:ImageButton>
<asp:ImageButton id="ImageButton3" runat="server" ImageUrl="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\publishbook1.gif"></asp:ImageButton></FONT></P">file:///C:\Inetpub\wwwroot\ebook\Pic\publishbook1.gif"></asp:ImageButton></FONT></P>
</FONT>
</TD>
</TR>
</TABLE>
<TABLE cellSpacing="1" cellPadding="4" width="805" border="0">
<!--DWLayoutTable-->
<TR>
<TD width="805" bgColor="#ccffff" height="25"><FONT size="3">
<P><FONT size="3">&nbsp;
<asp:label id="lblWelcome" runat="server" Width="232px" Font-Size="X-Small" Font-Names="Time news roman"
Font-Bold="True"></asp:label>User Type:
<asp:label id="Labelutype" runat="server" Width="120px"></asp:label></FONT></P>
</FONT>
</TD>
</TR>
</TABLE>
<TABLE cellSpacing="0" cellPadding="0" width="705" align="center" border="0"> <!--DWLayoutTable-->
<TBODY>
<TR>
<TD style="HEIGHT: 19px" align="center" width="705" height="19"><font size="4"><asp:label id="msg" runat="server" Width="517px" Font-Names="times new roman" ForeColor="#ff0033"></asp:label></font></TD>
</TR>
<tr>
<td align="center" width="705" height="65"><asp:datagrid id="comment" runat="server" Width="705px" Font-Size="X-Small" Font-Names="times new roman"
AllowPaging="True" OnPageIndexChanged="newPage" PageSize="20" BorderColor="LightGray" AutoGenerateColumns="False" CellPadding="4"
Font-Name="times new roman" HorizontalAlign="Center" BackColor="WhiteSmoke">
<AlternatingItemStyle Font-Size="X-Small" Font-Names="Times New Roman" BackColor="Transparent"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="MediumOrchid"></HeaderStyle>
<Columns>
<asp:BoundColumn Visible="False" DataField="Comment"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<table width="260">
<tr>
<td>Post By:</td>
<td><%# Container.DataItem("PostBy")%></td>
</tr>
<tr>
<td>Last Post:</td>
<td><%# Container.DataItem("PostDate")%></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Comment" HeaderText="Comment">
<ItemStyle Width="495px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="">
<ItemTemplate>
<asp:HyperLink runat="server" ID="Hyperlink1" Text=Edit NavigateUrl='<%# "admineditcomment.aspx?BookId=" & _
Container.DataItem("BookId")& _
"&CommentId=" & Container.DataItem("CommentId")%>' />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible="False" DataField="CommentId"></asp:BoundColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete" HeaderText="Delete">
<HeaderStyle Wrap="False"></HeaderStyle>
<ItemStyle Wrap="False" Width="80px"></ItemStyle>
</asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" ForeColor="White" BackColor="Thistle" Mode="NumericPages"></PagerStyle>
</asp:datagrid></td>
</tr>
</TBODY>
</TABLE>
<BR>
<table width="705" align="center" border="1">
<TBODY>
<tr>
<td>Add Comment:</td>
<td><asp:textbox id="TextComment" runat="server" Width="500px" BorderColor="Silver" Height="100px"
MaxLength="50" TextMode="MultiLine"></asp:textbox></td>
</tr>
<tr>
<td align="center" colSpan="2"><INPUT style="WIDTH: 55px; HEIGHT: 25px" type="reset" value="Reset">
<asp:button id="submit" runat="server" Height="26px" Text="Submit"></asp:button></td>
</tr>
</TBODY>
</table>
</form>
</td>
</tr>
</TBODY>
</table>
</body>
</HTML>
 
 
aspx.vb:
Imports System.Data
Imports System.Data.SqlClient
 
Public Class AdminAddComment
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents lblWelcome As System.Web.UI.WebControls.Label
Protected WithEvents msg As System.Web.UI.WebControls.Label
Protected WithEvents comment As System.Web.UI.WebControls.DataGrid
Protected WithEvents TextComment As System.Web.UI.WebControls.TextBox
Protected WithEvents submit As System.Web.UI.WebControls.Button
Protected WithEvents viewAns As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents Labelutype As System.Web.UI.WebControls.Label
Protected WithEvents ImageButton1 As System.Web.UI.WebControls.ImageButton
Protected WithEvents ImageButton2 As System.Web.UI.WebControls.ImageButton
Protected WithEvents HyperLink6 As System.Web.UI.WebControls.HyperLink
Protected WithEvents HyperLink5 As System.Web.UI.WebControls.HyperLink
Protected WithEvents HyperLink4 As System.Web.UI.WebControls.HyperLink
Protected WithEvents HyperLink3 As System.Web.UI.WebControls.HyperLink
Protected WithEvents ImageButton3 As System.Web.UI.WebControls.ImageButton
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim strID As String
Dim cID As String
Dim strC As String
Dim MyConnection As SqlConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("DBConnection"))
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
lblWelcome.Text = "Welcome," & Session("sesName")
Labelutype.Text = Session("sesUType")
strID = CStr(Request.QueryString("BookId"))
cID = CStr(Request.QueryString("CommentId"))
If Not Page.IsPostBack Then
bindComment()
End If
End Sub
Sub bindComment()
Dim da As SqlDataAdapter
Dim ds As DataSet
 
Dim strselect As String = "SELECT * FROM Comment WHERE BookId='" & _
strID & "' order by PostDate asc"
da = New SqlDataAdapter(strselect, MyConnection)
ds = New DataSet
da.Fill(ds, "Comment")
If ds.Tables("Comment").Rows.Count = 0 Then
msg.Text = "No Comment! "
msg.Visible = True
End If
'bind datagrid
comment.DataSource = ds.Tables("Comment").DefaultView
comment.DataBind()
End Sub
 
Private Sub submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click
Dim strInsert As String
Dim cmdInsert As SqlCommand
strInsert = "INSERT INTO Comment(MemberId,UserType,BookId,Comment,PostBy,PostDate) values (@MemberId, @UserType, @BookId, @Comment, @PostBy, @PostDate)"
cmdInsert = New SqlCommand(strInsert, MyConnection)
 
cmdInsert.Parameters.Add(New SqlParameter("@MemberId", SqlDbType.Int, 4))
cmdInsert.Parameters("@MemberId").Value = Session("SESMemberId")
cmdInsert.Parameters.Add(New SqlParameter("@UserType", SqlDbType.Char, 10))
cmdInsert.Parameters("@UserType").Value = Session("sesUType")
cmdInsert.Parameters.Add(New SqlParameter("@BookId", SqlDbType.Int, 4))
cmdInsert.Parameters("@BookId").Value = Request.QueryString("BookId")
cmdInsert.Parameters.Add(New SqlParameter("@Comment", SqlDbType.VarChar, 50))
cmdInsert.Parameters("@Comment").Value = TextComment.Text
cmdInsert.Parameters.Add("@PostBy", SqlDbType.VarChar, 50).Value = Session("SESName")
cmdInsert.Parameters.Add(New SqlParameter("@PostDate", SqlDbType.DateTime, 8))
cmdInsert.Parameters("@PostDate").Value = DateTime.Now.ToString
MyConnection.Open()
cmdInsert.ExecuteNonQuery()
MyConnection.Close()
Response.Redirect("AdminAddComment.aspx?BookId=" & strID)
End Sub
Sub NewPage(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
comment.CurrentPageIndex = e.NewPageIndex
bindComment()
End Sub
Private Sub comment_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles comment.DeleteCommand
cID = CInt(e.Item.Cells(4).Text)
Dim strdel As String
Dim cmddel As SqlCommand
strdel = "delete from Comment WHERE CommentId=@CommentId AND BookId=@BookId "
cmddel = New SqlCommand(strdel, MyConnection)
 
cmddel.Parameters.Add(New SqlParameter("@BookId", SqlDbType.Int, 4))
cmddel.Parameters("@BookId").Value = strID
cmddel.Parameters.Add(New SqlParameter("@CommentId", SqlDbType.Int, 4))
cmddel.Parameters("@CommentId").Value = cID
MyConnection.Open()
cmddel.ExecuteNonQuery()
Response.Redirect("AdminAddComment.aspx?BookId=" & Request.QueryString("BookId"))
MyConnection.Close()
End Sub
Private Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Response.Redirect("AdminHome.aspx")
End Sub
Private Sub ImageButton2_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
Response.Redirect("AdminAuthoringTools.aspx")
End Sub
Private Sub ImageButton3_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton3.Click
Response.Redirect("upload.aspx")
End Sub
End Class

Check syntax of the following lines:(ImageUrl="...."... ???

<asp:HyperLink id="HyperLink3" runat="server" ImageUrl="<A href="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\editprofile1.gif">HyperLink</asp:HyperLink">file:///C:\Inetpub\wwwroot\ebook\Pic\editprofile1.gif">HyperLink</asp:HyperLink">file:///C:\Inetpub\wwwroot\ebook\Pic\editprofile1.gif">HyperLink</asp:HyperLink">file:///C:\Inetpub\wwwroot\ebook\Pic\editprofile1.gif">HyperLink</asp:HyperLink>
<asp:ImageButton id="ImageButton2" runat="server" ImageUrl="<A href="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\authoring.gif"></asp:ImageButton">file:///C:\Inetpub\wwwroot\ebook\Pic\authoring.gif"></asp:ImageButton">file:///C:\Inetpub\wwwroot\ebook\Pic\authoring.gif"></asp:ImageButton">file:///C:\Inetpub\wwwroot\ebook\Pic\authoring.gif"></asp:ImageButton>
<asp:ImageButton id="ImageButton3" runat="server" ImageUrl="<A href="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\publishbook1.gif"></asp:ImageButton></FONT></P">file:///C:\Inetpub\wwwroot\ebook\Pic\publishbook1.gif"></asp:ImageButton">file:///C:\Inetpub\wwwroot\ebook\Pic\publishbook1.gif"></asp:ImageButton></FONT></P">file:///C:\Inetpub\wwwroot\ebook\Pic\publishbook1.gif"></asp:ImageButton>

image button coding now as below..but now still got the same problem...Help!!

<asp:imagebutton id="ImageButton1" runat="server" ImageUrl="file:///C:\Inetpub\wwwroot\ebook\Pic\Home1.gif"
Width="96px"></asp:imagebutton>
<asp:HyperLink id="HyperLink3" runat="server" ImageUrl="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\editprofile1.gif">HyperLink</asp:HyperLink">file:///C:\Inetpub\wwwroot\ebook\Pic\editprofile1.gif">HyperLink</asp:HyperLink>
<asp:HyperLink id="HyperLink4" runat="server" ImageUrl="file:///C:\Inetpub\wwwroot\ebook\Pic\searchbook1.gif"
NavigateUrl="SearchBook.aspx">HyperLink</asp:HyperLink>
<asp:HyperLink id="HyperLink5" runat="server" ImageUrl="file:///C:\Inetpub\wwwroot\ebook\Pic\viewnotice1.gif"
NavigateUrl="ViewNotice.aspx">HyperLink</asp:HyperLink>
<asp:HyperLink id="HyperLink6" runat="server" ImageUrl="file:///C:\Inetpub\wwwroot\ebook\Pic\deletebook1.gif"
NavigateUrl="DeleteBook.aspx">HyperLink</asp:HyperLink>
<asp:ImageButton id="ImageButton2" runat="server" ImageUrl="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\authoring.gif"></asp:ImageButton">file:///C:\Inetpub\wwwroot\ebook\Pic\authoring.gif"></asp:ImageButton>
<asp:ImageButton id="ImageButton3" runat="server" ImageUrl="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\publishbook1.gif"></asp:ImageButton">file:///C:\Inetpub\wwwroot\ebook\Pic\publishbook1.gif"></asp:ImageButton>

<asp:HyperLink id="HyperLink3" runat="server" ImageUrl="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\editprofile1.gif">HyperLink</asp:HyperLink">file:///C:\Inetpub\wwwroot\ebook\Pic\editprofile1.gif">HyperLink</asp:HyperLink>
 
<asp:ImageButton id="ImageButton2" runat="server" ImageUrl="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\authoring.gif"></asp:ImageButton">file:///C:\Inetpub\wwwroot\ebook\Pic\authoring.gif"></asp:ImageButton>
 
<asp:ImageButton id="ImageButton3" runat="server" ImageUrl="<A href="file:///C:\Inetpub\wwwroot\ebook\Pic\publishbook1.gif"></asp:ImageButton">file:///C:\Inetpub\wwwroot\ebook\Pic\publishbook1.gif"></asp:ImageButton>

Where are starting tags for the last ending tags of the "</asp:HyperLink>" and "</asp:ImageButton>" ?? (lines 5,12 and 13 in your code)

actually the problem u mention is not occur...don know y when i copy the code inside here will authomatically change like this... But this problem wat i met is b4 i put all this image button o.....

i know...but i still cannot found the problem out....Help!!!!!!!!!!

The error states Object not declared.... On Line 41 and Char 3. Where is that in your code?

Provide the text from the error message you took a screen shot of, this will help us narrow things down.

Just as an FYI for future postings of code, the region of your code labeled with : #Region " Web Form Designer Generated Code " is a region you don't need to provide. Try to post the code that is relevant or related to the issue. I know you want to provide as much detail as possible, but being concise can help speed up resolution to your problem.

NOTE ** you should avoid using "actual" links versus relative links to items in your web page. This will greatly reduce the number of possible sources of error.

i.e. href="file:///C:\Inetpub\wwwroot\ebook\Pic\authoring.gif (absolute link)

This should be written as href="/Pic/authoring.gif" (relative link - note the slash difference)

The method used is appropriate from a opening of the file in windows explorer, not so good for a web server which is using relative addresses and not absolute (or actual) addresses.

Hope this helps

if view source from internet exporer, the line 41 is like the line which i bold below:

<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["viewAns"];
}
else {
theform = document.viewAns;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// -->
</script>

This code is not in my coding in asp.net

the problem is because you deleted the form in your html code. You have no form therefore you cant postback to the server.
As you have no form the postback script you hightlighted couldnt find the form so couldnt get the viewstate.
Why did you delete it?
You have to have a form to have asp pages.

This article has been dead for over six months. Start a new discussion instead.