Hi guys

Im developing a site in ASP.NET, I have a form that is used both for (Add
& Edit). I put Old Values for Edit in the form, but when user submits that
back after changing, It shows me Old Values.

and when I dont put any Value(as I do for "ADD-New-Record") it picks new
values as it should do For "Edit-Record" as well.

waiting for reply.

Thanks in Advance

Faisal

My code is here

Public Class MemberPath
Inherits System.Web.UI.Page
Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton
Protected WithEvents LinkButton2 As System.Web.UI.WebControls.LinkButton
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents emailLbl As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label6 As System.Web.UI.WebControls.Label
Protected WithEvents Label8 As System.Web.UI.WebControls.Label
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator4 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents Label9 As System.Web.UI.WebControls.Label
Protected WithEvents Label12 As System.Web.UI.WebControls.Label
Protected WithEvents Label14 As System.Web.UI.WebControls.Label
Protected WithEvents RegularExpressionValidator1 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents RegularExpressionValidator2 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents RegularExpressionValidator5 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents Submit As System.Web.UI.WebControls.Button
Protected WithEvents pReachDate As System.Web.UI.WebControls.TextBox
Protected WithEvents pStartDate As System.Web.UI.WebControls.TextBox
Protected WithEvents pStatus As System.Web.UI.WebControls.TextBox
Protected WithEvents pReachTime As System.Web.UI.WebControls.TextBox
Protected WithEvents pTo As System.Web.UI.WebControls.TextBox
Protected WithEvents pFrom As System.Web.UI.WebControls.TextBox
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Private m As New Member()
Private j As New MemberJourney()
Protected WithEvents pathtype As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents pcomments As System.Web.UI.WebControls.TextBox
Protected WithEvents PisOver As System.Web.UI.WebControls.CheckBox
Private dopath As String
Private p As Path
Private pid As Int32

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

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

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
j = Session.Item("journey")
If j Is Nothing Then
'Disable all fields
Response.Write("No Journey is Selected")
Me.disableForm()
pathtype.Enabled = False
Else
m.MemberID = j.MemberId
m.FllMemberFromDB(m.MemberID, ConfigurationSettings.AppSettings("dsn"))
emailLbl.Text = m.MemberEmail
Dim FPdata As DataSet
Dim RPdata As DataSet

Dim s As String = Session.Item("pathtype")
dopath = Session.Item("dopath")

If s Is Nothing Or dopath Is Nothing Then
Response.Write("No path is selected")
Me.disableForm()
ElseIf s.Equals("forward") And dopath.Equals("insert") Then
ForwardInsert()
ElseIf s.Equals("return") And dopath.Equals("insert") Then
ReturnInsert()
ElseIf s.Equals("forward") And dopath.Equals("update") Then
ForwardUpdate()
ElseIf s.Equals("return") And dopath.Equals("update") Then
ReturnUpdate()
End If

End If
End Sub

Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Submit.Click

If pathtype.Text.Equals("Forward Path") = True Then
p = New ForwardPath()
ElseIf pathtype.Text.Equals("Return Path") = True Then
p = New ReturnPath()
End If
'get Values from Form
If dopath.Equals("insert") Then
fromForm(p)
p.MemberID = m.MemberID
p.JourneyId = j.JourneyId
InsertPath(p)
ElseIf dopath.Equals("update") Then
p.FllPathFromDB(pid, ConfigurationSettings.AppSettings("dsn"))
fromForm(p)
UpdatePath(p)
End If
End Sub

Private Sub disableForm()
pFrom.Enabled = False
pTo.Enabled = False
pStartDate.Enabled = False
pReachDate.Enabled = False
pReachTime.Enabled = False
pStatus.Enabled = False
Submit.Enabled = False
End Sub
Private Sub enableForm()
pFrom.Enabled = True
pTo.Enabled = True
pStartDate.Enabled = True
pReachDate.Enabled = True
pReachTime.Enabled = True
pStatus.Enabled = True
Submit.Enabled = True
End Sub
Private Sub toForm(ByRef p As Path)
m.MemberID = p.MemberID
j.JourneyId = p.JourneyId
pFrom.Text = p.FromStation.Replace("'", "''")
pTo.Text = p.ToStation.Replace("'", "''")
pStartDate.Text = p.StartingDate
pReachDate.Text = p.ReachingDate
pReachTime.Text = p.ReachingTime
pStatus.Text = p.Status.Replace("'", "''")
pcomments.Text = p.Comments.Replace("'", "''")
PisOver.Checked = p.isOver
End Sub
Private Sub fromForm(ByRef p As Path)

p.FromStation = pFrom.Text.Replace("'", "''")
p.ToStation = pTo.Text.Replace("'", "''")
p.StartingDate = CDate(pStartDate.Text)
p.ReachingDate = CDate(pReachDate.Text & " " & pReachTime.Text)
p.ReachingTime = CDate(pReachDate.Text & " " & pReachTime.Text)
p.Status = pStatus.Text.Replace("'", "''")
p.Comments = pcomments.Text.Replace("'", "''")
p.isOver = PisOver.Checked
End Sub

Private Sub ReturnInsert()
pathtype.Text = "Return Path"
Me.enableForm()
Me.pathtype.Enabled = True
LinkButton1.Visible = False
LinkButton2.Visible = False
End Sub
Private Sub ReturnUpdate()
p = Session.Item("path")
If p Is Nothing Then
disableForm()
Else
'toForm(p)
pid = p.PathId
pathtype.Text = "Return Path"
Me.enableForm()
Me.pathtype.Enabled = False
LinkButton1.Visible = False
LinkButton2.Visible = False
End If
End Sub


Private Sub ForwardInsert()
pathtype.Text = "Forward Path"
Me.enableForm()
Me.pathtype.Enabled = True
LinkButton1.Visible = False
LinkButton2.Visible = False
End Sub
Private Sub ForwardUpdate()
p = Session.Item("path")
If p Is Nothing Then
disableForm()
Else
'toForm(p)
pid = p.PathId
pathtype.Text = "Forward Path"
Me.enableForm()
Me.pathtype.Enabled = False
LinkButton1.Visible = False
LinkButton2.Visible = False
End If
End Sub

Private Sub InsertPath(ByRef p As Path)
Dim b As Boolean = p.AddPath(ConfigurationSettings.AppSettings("dsn"))
If b Then
Session.Add("msg", "Record Inserted")
Else
Session.Add("msg", "Insertion Failes")
End If
Response.Redirect("registered.aspx")
End Sub
Private Sub UpdatePath(ByRef p As Path)
p.PathId = pid
Dim b As Boolean = p.UpdatePath(ConfigurationSettings.AppSettings("dsn"))
If b Then
Session.Add("msg", "Record Updated")
Else
Session.Add("msg", "Updation Failed")
End If
Response.Redirect("registered.aspx")
End Sub


End Class