468,505 Members | 1,696 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

response redirect without asking

I have a datagrid with update/cancel on one side, a button on the
other which, when clicked, will take the user to a page that allows
them to e-mail that particular observation's data. My problem, is
that I have some columns that are sortable. To make everything work,
I can wrap the e-mail code in a 'if not.postback' statement (wrong I
know--testing here), but then, my sorts/updates/cancels don't work
because an error is thrown from the page I redirect to . . . even
though I haven't pressed the e-mail button. For example, for the code
I post below, if I sort a row, an error is thrown from code within the
sendmail.aspx page. I don't understand this and can't step through it
(using Dreamweaver).

I'm sure I'm doing something really silly. Any help is appreciated.

<%@ Page Language="VB" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<%@ Import Namespace="System.Web.Mail" %>
<script language="VB" runat="server">
Sub MyDataGrid_EditCommand(s As Object, e As DataGridCommandEventArgs
)
MyDataGrid.EditItemIndex = e.Item.ItemIndex
BindData("zyp9.Outbreak.DtRpt DESC")
End Sub

Sub MyDataGrid_Cancel(Source As Object, E As DataGridCommandEventArgs)
MyDataGrid.EditItemIndex = -1
BindData("zyp9.Outbreak.DtRpt DESC")
End Sub

Sub Page_Load(Source as Object, E as EventArgs)
if not Page.IsPostBack then
BindData("zyp9.Outbreak.DtRpt DESC")
end if
End Sub

Sub Page_Change(sender As Object, e As DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindData("zyp9.Outbreak.DtRpt DESC")
End Sub

Sub BindData( strSortField as String )
Dim strConn as string =
"server=DEV1;uid=user;pwd=xxx;database=OUTBREA K"
Dim sql as string = "SELECT zyp9.Outbreak.RowId,
zyp9.Outbreak.Title, zyp9.Outbreak.State, zyp9.Outbreak.Sts_Af, " & _
"zyp9.Outbreak.DtRpt, zyp9.Outbreak.Disease,
zyp9.Outbreak.Type, zyp9.Outbreak.Cases, " & _
"zyp9.Outbreak.Alias, zyp9.Email.lname + ', ' +
zyp9.Email.fname as Name " & _
"FROM zyp9.Outbreak, zyp9.email " & _
"WHERE (zyp9.Outbreak.alias=zyp9.Email.alias) " & _
"ORDER BY " & strSortField
Dim conn as New SQLConnection(strConn)
Dim objDR as SQLDataReader
Dim Cmd as New SQLCommand(sql, conn)
conn.Open()
objDR=Cmd.ExecuteReader(system.data.CommandBehavio r.CloseConnection)
MyDataGrid.DataSource = objDR
MyDataGrid.DataBind()
conn.close
End Sub

Sub dgSort( s As object, e as DataGridSortCommandEventArgs)
BindData (e.SortExpression)
End Sub

Sub MyDataGrid_UpdateCommand(s As Object, e As
DataGridCommandEventArgs )
Dim conn As SqlConnection
Dim Cmd As SqlCommand
Dim strConn as string =
"server=DEV1;uid=user;pwd=xxx;database=OUTBREA K"
Dim txtTitle As textbox = E.Item.cells(2).Controls(0)
Dim txtState As textbox = E.Item.cells(3).Controls(0)
Dim txtSts_Af As textbox = E.Item.cells(4).Controls(0)
Dim txtDtRpt As textbox = E.Item.cells(5).Controls(0)
Dim txtDisease As textbox = E.Item.cells(6).Controls(0)
Dim txtType As textbox = E.Item.cells(7).Controls(0)
Dim txtCases As textbox = E.Item.cells(8).Controls(0)
Dim strUpdateStmt As String
strUpdateStmt ="UPDATE zyp9.Outbreak SET Title =@Title, State
=@State, Sts_Af =@Sts_Af, " & _
"DtRpt =@DtRpt, Disease=@Disease, Type=@Type,
Cases=@Cases " & _
"WHERE RowId = @RowId"
conn = New SqlConnection(strConn)
Cmd = New SqlCommand(strUpdateStmt, conn)
Cmd.Parameters.Add(New SQLParameter("@Title", txtTitle.text))
Cmd.Parameters.Add(New SQLParameter("@State", txtState.text))
Cmd.Parameters.Add(New SQLParameter("@Sts_Af", txtSts_Af.text))
Cmd.Parameters.Add(New SQLParameter("@DtRpt", txtDtRpt.text))
Cmd.Parameters.Add(New SQLParameter("@Disease", txtDisease.text))
Cmd.Parameters.Add(New SQLParameter("@Type", txtType.text))
Cmd.Parameters.Add(New SQLParameter("@Cases", txtCases.text))
Cmd.Parameters.Add(New SQLParameter("@RowID", e.Item.Cells(1).Text))
conn.Open()
Cmd.ExecuteNonQuery()
MyDataGrid.EditItemIndex = -1
conn.close
BindData("zyp9.Outbreak.RptDt DESC")
End Sub

Sub Email_Report(s As Object, e As DataGridCommandEventArgs)
Dim strRowID As string = E.Item.cells(1).text
Dim strAlias as string = E.Item.cells(10).text

'If Not Page.IsPostBack Then
e.Item.Backcolor = system.drawing.color.lightgreen
e.item.font.bold = true
Response.Redirect("SendMail.aspx?RowId=" &
System.Web.HttpUtility.UrlEncode(strRowId) _
& "&Alias=" &
System.Web.HttpUtility.UrlEncode(strAlias))
'End If
End Sub
</script>

<html>
<head>
<title>Entry Edit</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<table width="263" border="1" align="center" id="nav_bar">
<tr>
<td height="22" colspan="2">
<div align="center">
<font color="#333366" size="3" face="Geneva, Arial, Helvetica,
sans-serif">
<strong>Outbreak Entry Report</strong>
</font>
</div>
</td>
</tr>
<tr>
<td width="122">
<div align="center">
<font color="#333366" size="3" face="Geneva, Arial, Helvetica,
sans-serif">
<strong>
<a href="http://acid-xdv-webdv1/hepatitis/default.htm">Home</a>
</strong>
</font>
</div>
</td>
<td width="125">
<div align="center"> <font color="#333366" size="3" face="Geneva,
Arial, Helvetica, sans-serif">
<strong><a href="http://acid-xdv-webdv1/hepatitis/default.htm">Xyz</a></strong>
</font> </div>
</td>
</tr>
</table>
<hr>
<form name="form1" method="post" runat="server">
<asp:Datagrid runat="server"
Id="MyDataGrid"
GridLines="Both"
cellpadding="2"
cellspacing="2"
Headerstyle-BackColor="#8080C0"
Headerstyle-Font-Name="Arial"
Headerstyle-Font-Size="12"
Headerstyle-Font-Bold="True"
AutogenerateColumns="False"
OnEditcommand="MyDataGrid_EditCommand"
OnCancelcommand="MyDataGrid_Cancel"
OnUpdateCommand="MyDataGrid_UpdateCommand"
OnItemCommand="Email_Report"
OnPageIndexChanged="Page_Change"
AllowSorting = "True"
OnSortCommand ="dgSort"
DataKeyField="RowId">
<ItemStyle BackColor="#F2F2F2" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<AlternatingItemStyle BackColor="#E5E5E5"
Font-Name="Verdana, Arial, Helvetica,
sans-serif"
Font-Size="smaller" />
<Columns>
<asp:EditCommandColumn
ButtonType="LinkButton"
UpdateText="Update"
CancelText="Cancel"
EditText="<IMG SRC='pics/Edit.gif' Border=0 Width=12 Height=12>"
ItemStyle-HorizontalAlign="Center"
HeaderText="Edit">
</asp:EditCommandColumn>
<asp:BoundColumn
DataField="RowId"
HeaderText="ID"
ReadOnly="True"
SortExpression="zyp9.Outbreak.RowId">
</asp:BoundColumn>
<asp:BoundColumn
DataField="Title"
HeaderText="Title">
</asp:BoundColumn>
<asp:BoundColumn
DataField="State"
HeaderText="State">
</asp:BoundColumn>
<asp:BoundColumn
DataField="Sts_Af"
HeaderText="Other States">
</asp:BoundColumn>
<asp:BoundColumn
DataField="DtRpt"
HeaderText="Date Rptd"
DataFormatString="{0:d}"
SortExpression="zyp9.Outbreak.DtRpt DESC">
</asp:BoundColumn>
<asp:BoundColumn
DataField="Disease"
HeaderText="Disease">
</asp:BoundColumn>
<asp:BoundColumn
DataField="Type"
HeaderText="Type">
</asp:BoundColumn>
<asp:BoundColumn
DataField="Cases"
HeaderText="Cases">
</asp:BoundColumn>
<asp:BoundColumn
DataField="Name"
HeaderText="Recipient"
ReadOnly="True"
SortExpression="zyp9.Email.LName">
</asp:BoundColumn>
<asp:BoundColumn
DataField="Alias"
HeaderText="Alias"
ReadOnly="True">
</asp:BoundColumn>
<asp:ButtonColumn
Text="<IMG SRC='pics/email05a.gif' Border=0 Width=20
Height=20>"
ItemStyle-HorizontalAlign="Center"
HeaderText="E-Mail"
CommandName="Email">
</asp:ButtonColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
Nov 17 '05 #1
0 2325

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Justin | last post: by
3 posts views Thread by Grant | last post: by
12 posts views Thread by gigi | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.