Update pressed no data saved and reverts back to old data - asp.net

I am having trouble with "Sub GridView1_OnRowUpdating".
When in Edit is pressed, the data in a cell is changed, and the Update is pressed the data reverts back to its original data and no data is stored.
<asp:GridView ID="GridView1" runat="server" AllowSorting="true" AutoPostBack="True" AutoGenerateColumns="True" AutoGenerateEditButton="True" OnRowCancelingEdit="Gridview1_OnRowCancelingEdit" OnRowEditing="Gridview1_OnRowEditing" OnRowUpdating="GridView1_OnRowUpdating"
AllowPaging="True" PageSize="50" OnPageIndexChanging="GridView1_PageIndexChanging">
</asp:GridView>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
ViewState("pageIndex") = 1
ViewState("edit") = -1
ShowGrid()
End If
End Sub
Sub ShowGrid()
Dim connStr, cmdStr As String
connStr = "connection string works"
cmdStr = "SELECT * FROM OrbitDates;"
Dim ds As New DataSet
Dim dt As New DataTable()
Try
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand(cmdStr, conn)
conn.Open()
cmd.ExecuteNonQuery()
Using da As New SqlDataAdapter(cmd)
da.Fill(ds)
dt = ds.Tables(0)
GridView1.EditIndex = Convert.ToInt32(ViewState("edit"))
GridView1.DataSource = dt
GridView1.DataBind()
GridView1.PageIndex = Convert.ToInt32(ViewState("pageIndex"))
End Using
conn.Close()
cmd.Dispose()
conn.Dispose()
End Using
End Using
Catch ex As Exception
End Try
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
ViewState("pageIndex") = e.NewPageIndex.ToString()
ShowGrid()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
ViewState("pageIndex") = 1
ShowGrid()
End Sub
Protected Sub GridView1_OnRowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.EditIndex = e.NewEditIndex
ViewState("edit") = GridView1.EditIndex
ShowGrid()
End Sub
Protected Sub GridView1_OnRowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
GridView1.EditIndex = -1
ViewState("edit") = GridView1.EditIndex
ShowGrid()
End Sub
Protected Sub GridView1_OnRowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim connStr, cmdStr As String
connStr = "connection string works"
cmdStr = "UPDATE OrbitDates SET JD=#JD,Xecl1=#Xecl1,Yecl1=#Yecl1,Zecl1=#Zecl1 WHERE ido=#ido;"
Try
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand(cmdStr, conn)
conn.Open()
cmd.Parameters.AddWithValue("#ido", GridView1.Rows(e.RowIndex).Cells(0).Text)
cmd.Parameters.AddWithValue("#JD", GridView1.Rows(e.RowIndex).Cells(1).Text)
cmd.Parameters.AddWithValue("#Xecl1", GridView1.Rows(e.RowIndex).Cells(2).Text)
cmd.Parameters.AddWithValue("#Yecl1", GridView1.Rows(e.RowIndex).Cells(3).Text)
cmd.Parameters.AddWithValue("#Zecl1", GridView1.Rows(e.RowIndex).Cells(4).Text)
cmd.ExecuteNonQuery()
conn.Close()
cmd.Dispose()
conn.Dispose()
End Using
End Using
Catch ex As Exception
Throw ex
End Try
ViewState("edit") = e.RowIndex
ShowGrid()
End Sub

Related

how can we access form2 listbox (lb1) in form3

Imports System.Windows.Forms.ListBox
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mf1 As New Form3()
Form3.Visible = True
Me.Hide()
End Sub
Imports System.Data.OleDb
Public Class Form3
Private Class dataaccess
Public Shared Function getconnection() As OleDbConnection
'string constr = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\database\Database2007.accdb";
Dim constr1 As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Suman\Desktop\vs ws\vb\project_sample1\Database1.accdb"
Return New OleDbConnection(constr1)
End Function
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As OleDbConnection = dataaccess.getconnection()
Dim query As String = "SELECT * FROM Burgers"
Dim cmd As New OleDbCommand(query, con)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet()
' Dim x As Integer
da.Fill(ds)
**lb1**.Items.Add(ds.Tables(0).Rows(0).ItemArray(0).ToString())
End Sub
I want to store the form 3 data into lb1 listbox which is declared in the form 2
You can pass a reference to that specific listbox or the entire form2 to form3. the easy way is to write it into the constructor of the form.
In Form3:
private _TargetListBox as ListBox
public sub New(ByRef TargetListBox as ListBox)
_TargetListBox = TargetListBox
end sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As OleDbConnection = dataaccess.getconnection()
Dim query As String = "SELECT * FROM Burgers"
Dim cmd As New OleDbCommand(query, con)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet()
' Dim x As Integer
da.Fill(ds)
_TargetListBox.Items.Add(ds.Tables(0).Rows(0).ItemArray(0).ToString())
End Sub
In Form2:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mf1 As New Form3(Me.lb1)
mf1.Visible = True
Me.Hide()
End Sub

Edit and update my SQL Server database with the edit and update

I have a SQL Server table with 5 columns. col1 is the primary key. I an working in ASP.net 4.0.
I want to be able to edit and update my SQL Server table with the edit and update respectively.
I am having a little trouble with the update. Here is my code:
<asp:GridView ID="GridView1" runat="server" AutoPostBack="True" AutoGenerateColumns="True" AutoGenerateEditButton="True" OnRowEditing="Gridview1_OnRowEditing" OnRowUpdating="GridView1_OnRowUpdating">
</asp:GridView>
Code:
Sub ShowGrid()
Dim connStr, cmdStr As String
connStr = "connection string works"
cmdStr = "SELECT * FROM table1;"
Dim MyDataSet As New DataSet
Dim MyDataTable As New DataTable()
Try
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand(cmdStr, conn)
conn.Open()
cmd.ExecuteNonQuery()
Using MyDataAdaptor As New SqlDataAdapter(cmd)
MyDataAdaptor.Fill(MyDataSet)
MyDataTable = MyDataSet.Tables(0)
GridView1.EditIndex = Convert.ToInt32(ViewState("edit"))
GridView1.DataSource = MyDataTable
GridView1.DataBind()
End Using
conn.Close()
cmd.Dispose()
conn.Dispose()
End Using
End Using
Catch ex As Exception
Throw ex
End Try
End Sub
Protected Sub GridView1_OnRowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
GridView1.EditIndex = e.NewEditIndex
ViewState("edit") = GridView1.EditIndex
ShowGrid()
End Sub
Protected Sub GridView1_OnRowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Dim connStr, cmdStr As String
connStr = "connection string works"
cmdStr = "UPDATE table1 SET (col2=#col2,col3=#col3,col4=#col4,col5=#col5) WHERE col1=#col1;"
Try
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand(cmdStr, conn)
conn.Open()
cmd.Parameters.AddWithValue("#col1", GridView1.Rows(e.RowIndex).Cells(0).Text)
cmd.Parameters.AddWithValue("#col2", GridView1.Rows(e.RowIndex).Cells(1).Text)
cmd.Parameters.AddWithValue("#col3", GridView1.Rows(e.RowIndex).Cells(2).Text)
cmd.Parameters.AddWithValue("#col4", GridView1.Rows(e.RowIndex).Cells(3).Text)
cmd.Parameters.AddWithValue("#col5", GridView1.Rows(e.RowIndex).Cells(4).Text)
cmd.ExecuteNonQuery()
conn.Close()
cmd.Dispose()
conn.Dispose()
End Using
End Using
Catch ex As Exception
End Try
ViewState("edit") = e.RowIndex
ShowGrid()
End Sub

Gridview Editing Update to MS SQL database

I am having trouble with OnRowUpdating event. It will not save the new data in the GridView1.EditIndex row. It just reverts back to the old value as soon as you press Update.
The OnRowEditing seems to be functioning correctly.
The same goes for OnRowCancelingEdit it seems to be functioning correctly.
ASPX:
<asp:GridView ID="GridView1" runat="server" AllowSorting="true" AutoPostBack="True" AutoGenerateColumns="True" AutoGenerateEditButton="True" OnRowCancelingEdit="Gridview1_OnRowCancelingEdit" OnRowEditing="Gridview1_OnRowEditing" OnRowUpdating="GridView1_OnRowUpdating"
AllowPaging="True" PageSize="50" OnPageIndexChanging="GridView1_PageIndexChanging">
</asp:GridView>
Code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ViewState("pageIndex") = 1
ViewState("edit") = -1
ShowGrid()
End Sub
Sub ShowGrid()
Dim connStr, cmdStr As String
connStr = connection string works"
cmdStr = "SELECT * FROM OrbitDates;"
Dim ds As New DataSet
Dim dt As New DataTable()
Try
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand(cmdStr, conn)
conn.Open()
cmd.ExecuteNonQuery()
Using da As New SqlDataAdapter(cmd)
da.Fill(ds)
dt = ds.Tables(0)
GridView1.EditIndex = Convert.ToInt32(ViewState("edit"))
dt.DefaultView.Sort = ViewState("Sort")
GridView1.DataSource = dt.DefaultView
GridView1.DataBind()
GridView1.PageIndex = Convert.ToInt32(ViewState("pageIndex"))
End Using
conn.Close()
cmd.Dispose()
conn.Dispose()
End Using
End Using
Catch ex As Exception
End Try
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
ViewState("pageIndex") = e.NewPageIndex.ToString()
ShowGrid()
End Sub
Protected Sub GridView1_OnRowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
GridView1.EditIndex = e.NewEditIndex
ViewState("edit") = GridView1.EditIndex
ShowGrid()
End Sub
Protected Sub GridView1_OnRowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs)
GridView1.EditIndex = -1
ViewState("edit") = GridView1.EditIndex
ShowGrid()
End Sub
Protected Sub GridView1_OnRowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Dim connStr, cmdStr As String
connStr = "connection string works"
cmdStr = "UPDATE OrbitDates SET (JD=#JD,Xecl1=#Xecl1,Yecl1=#Yecl1,Zecl1=#Zecl1) WHERE ido=#ido;"
Try
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand(cmdStr, conn)
conn.Open()
cmd.Parameters.AddWithValue("#ido", GridView1.Rows(e.RowIndex).Cells(0).Text)
cmd.Parameters.AddWithValue("#JD", GridView1.Rows(e.RowIndex).Cells(1).Text)
cmd.Parameters.AddWithValue("#Xecl1", GridView1.Rows(e.RowIndex).Cells(2).Text)
cmd.Parameters.AddWithValue("#Yecl1", GridView1.Rows(e.RowIndex).Cells(3).Text)
cmd.Parameters.AddWithValue("#Zecl1", GridView1.Rows(e.RowIndex).Cells(4).Text)
cmd.ExecuteNonQuery()
conn.Close()
cmd.Dispose()
conn.Dispose()
End Using
End Using
Catch ex As Exception
Throw ex
End Try
ViewState("edit") = e.RowIndex
ShowGrid()
End Sub
The problem is the GridView is overwritten with the old data before executing GridView1_OnRowUpdating because of this code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ViewState("pageIndex") = 1
ViewState("edit") = -1
ShowGrid()
End Sub
You need to put If Not IsPostBack inside Page_Load:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
ViewState("pageIndex") = 1
ViewState("edit") = -1
ShowGrid()
End If
End Sub
Try to understand more about ASP.NET Page Life Cycle.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ViewState("pageIndex") = 1
ViewState("edit") = -1
ShowGrid()
End Sub
Sub ShowGrid()
Dim connStr, cmdStr As String
connStr = connection string works"
cmdStr = "SELECT * FROM OrbitDates;"
Dim ds As New DataSet
Dim dt As New DataTable()
Try
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand(cmdStr, conn)
conn.Open()
cmd.ExecuteNonQuery()
Using da As New SqlDataAdapter(cmd)
da.Fill(ds)
dt = ds.Tables(0)
GridView1.EditIndex = Convert.ToInt32(ViewState("edit"))
dt.DefaultView.Sort = ViewState("Sort")
GridView1.DataSource = dt.DefaultView
GridView1.DataBind()
GridView1.PageIndex = Convert.ToInt32(ViewState("pageIndex"))
End Using
conn.Close()
cmd.Dispose()
conn.Dispose()
End Using
End Using
Catch ex As Exception
End Try
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
ViewState("pageIndex") = e.NewPageIndex.ToString()
ShowGrid()
End Sub
Protected Sub GridView1_OnRowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
GridView1.EditIndex = e.NewEditIndex
ViewState("edit") = GridView1.EditIndex
ShowGrid()
End Sub
Protected Sub GridView1_OnRowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs)
GridView1.EditIndex = -1
ViewState("edit") = GridView1.EditIndex
ShowGrid()
End Sub
Protected Sub GridView1_OnRowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Dim connStr, cmdStr As String
connStr = "connection string works"
cmdStr = "UPDATE OrbitDates SET (JD=#JD,Xecl1=#Xecl1,Yecl1=#Yecl1,Zecl1=#Zecl1) WHERE ido=#ido;"
Try
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand(cmdStr, conn)
conn.Open()
cmd.Parameters.AddWithValue("#ido", GridView1.Rows(e.RowIndex).Cells(0).Text)
cmd.Parameters.AddWithValue("#JD", GridView1.Rows(e.RowIndex).Cells(1).Text)
cmd.Parameters.AddWithValue("#Xecl1", GridView1.Rows(e.RowIndex).Cells(2).Text)
cmd.Parameters.AddWithValue("#Yecl1", GridView1.Rows(e.RowIndex).Cells(3).Text)
cmd.Parameters.AddWithValue("#Zecl1", GridView1.Rows(e.RowIndex).Cells(4).Text)
cmd.ExecuteNonQuery()
conn.Close()
cmd.Dispose()
conn.Dispose()
End Using
End Using
Catch ex As Exception
Throw ex
End Try
ViewState("edit") = e.RowIndex
ShowGrid()
End Sub

VB dot net session value set in text box not change

In one of my vb page i am setting the value of a textbox through the value coming from session. In the same page i want to perform an edit operation of the record. On the page load i displayed the variables in textboxes and after editing values when i submit and take the value from the textboxes, it still take the value i set through session. It do not take the value changed in the textbox rather it shows the value assigned at the time of page load. Please help.
Here is my code,
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.SessionState.HttpSessionState
Imports System.Drawing
Imports System.Drawing.Printing
Partial Class Default2
Inherits System.Web.UI.Page
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
cn = New SqlConnection("Data Source=nnn-PC;Initial Catalog=Faculty Housing;Persist Security Info=True;User ID=sa;Password=nnn;")
cn.Open()
Dim var As String
var = Session("S2").ToString()
TextBox1.Text = var
Session.Remove("S2")
cmd = New SqlCommand("select * from HouseDetails where OccupantName= '" & TextBox1.Text & "' ", cn)
dr = cmd.ExecuteReader
While (dr.Read)
Label1.Text = dr(1)
Label2.Text = dr(2)
Label3.Text = dr(3)
TextBox3.Text = dr(4)
DropDownList3.SelectedItem.Text = dr(5)
TextBox2.Text = dr(6)
TextBox4.Text = dr(7)
TextBox5.Text = dr(8)
DropDownList4.Text = dr(9)
End While
cn.Close()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
cn = New SqlConnection("Data Source=nnn-PC;Initial Catalog=Faculty Housing;Persist Security Info=True;User ID=sa;Password=nnn;")
cn.Open()
Dim query As String = ("UPDATE HouseDetails SET OccupantName='" & TextBox1.Text & "' where HouseNum='" & Label3.Text & "'")
cmd = New SqlCommand(query, cn)
Dim x As Integer = cmd.ExecuteNonQuery()
cn.Close()
End Sub
Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
End Class
Add postback prevention with the line "If (Page.IsPostBack = false) Then", for not assigning the same value again to the textbox,
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.SessionState.HttpSessionState
Imports System.Drawing
Imports System.Drawing.Printing
Partial Class Default2
Inherits System.Web.UI.Page
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Page.IsPostBack = false) Then
cn = New SqlConnection("Data Source=nnn-PC;Initial Catalog=Faculty Housing;Persist Security Info=True;User ID=sa;Password=nnn;")
cn.Open()
Dim var As String
var = Session("S2").ToString()
TextBox1.Text = var
Session.Remove("S2")
cmd = New SqlCommand("select * from HouseDetails where OccupantName= '" & TextBox1.Text & "' ", cn)
dr = cmd.ExecuteReader
While (dr.Read)
Label1.Text = dr(1)
Label2.Text = dr(2)
Label3.Text = dr(3)
TextBox3.Text = dr(4)
DropDownList3.SelectedItem.Text = dr(5)
TextBox2.Text = dr(6)
TextBox4.Text = dr(7)
TextBox5.Text = dr(8)
DropDownList4.Text = dr(9)
End While
cn.Close()
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
cn = New SqlConnection("Data Source=nnn-PC;Initial Catalog=Faculty Housing;Persist Security Info=True;User ID=sa;Password=nnn;")
cn.Open()
Dim query As String = ("UPDATE HouseDetails SET OccupantName='" & TextBox1.Text & "' where HouseNum='" & Label3.Text & "'")
cmd = New SqlCommand(query, cn)
Dim x As Integer = cmd.ExecuteNonQuery()
cn.Close()
End Sub
Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
End Class
I fancy you're missing a check for IsPostBack to see whether or not this is a new request or a submission.
If (Not IsPostBack) Then
' populate for first load
End If
You have to put your code in IsPostback property.
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.SessionState.HttpSessionState
Imports System.Drawing
Imports System.Drawing.Printing
Partial Class Default2
Inherits System.Web.UI.Page
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (!IsPostBack) Then
cn = New SqlConnection("Data Source=nnn-PC;Initial Catalog=Faculty Housing;Persist Security Info=True;User ID=sa;Password=nnn;")
cn.Open()
Dim var As String
var = Session("S2").ToString()
TextBox1.Text = var
Session.Remove("S2")
cmd = New SqlCommand("select * from HouseDetails where OccupantName= '" & TextBox1.Text & "' ", cn)
dr = cmd.ExecuteReader
While (dr.Read)
Label1.Text = dr(1)
Label2.Text = dr(2)
Label3.Text = dr(3)
TextBox3.Text = dr(4)
DropDownList3.SelectedItem.Text = dr(5)
TextBox2.Text = dr(6)
TextBox4.Text = dr(7)
TextBox5.Text = dr(8)
DropDownList4.Text = dr(9)
End While
cn.Close()
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
cn = New SqlConnection("Data Source=nnn-PC;Initial Catalog=Faculty Housing;Persist Security Info=True;User ID=sa;Password=nnn;")
cn.Open()
Dim query As String = ("UPDATE HouseDetails SET OccupantName='" & TextBox1.Text & "' where HouseNum='" & Label3.Text & "'")
cmd = New SqlCommand(query, cn)
Dim x As Integer = cmd.ExecuteNonQuery()
cn.Close()
End Sub
Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
End Class

how to configure smtp settings

Imports System.Net.Mail
Partial Class ContactUs
Inherits System.Web.UI.Page
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim username = User.Identity.Name.ToString
Response.Redirect("~/ViewCart_aspx/ViewCart.aspx?userID=" & username)
End Sub
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
If txtComments.Text.Length > 200 Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub
Protected Sub WizardStep3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles WizardStep3.Load
lblName.text = txtName.Text
lblEmail.Text = txtEmail.Text
lblComments.Text = txtComments.Text
lblRating.Text = txtRatings.Text
End Sub
Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
SendMail(txtEmail.Text, txtComments.Text)
'MsgBox("Feedback Sent")
Response.Redirect("homepage_aspx/homepage.aspx")
End Sub
Private Sub SendMail(ByVal from As String, ByVal body As String)
Dim mMailSettings As System.Net.Configuration.MailSettingsSectionGroup
Dim mPort As Integer = mMailSettings.Smtp.Network.Port
Dim mHost As String = mMailSettings.Smtp.Network.Host
Dim mPassword As String = mMailSettings.Smtp.Network.Password
Dim mUsername As String = mMailSettings.Smtp.Network.UserName
'Dim mailServerName As String = "smtp.tricedeals.com"
'Dim message As MailMessage = New MailMessage(from, "admin#tricedeals.com", "feedback", body)
'Dim mailClient As SmtpClient = New SmtpClient
'mailClient.Host = mailServerName
'mailClient.Send(message)
'message.Dispose()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Cache.SetCacheability(HttpCacheability.NoCache)
End Sub
End Class
what is wrong with my smtp settings??i cant send emails.please help me.
you can't send email because the send command is commented out. since you don't give more details or better explanation or exception message that's the only thing I can assume.

Resources