I won't get notified if you answer my comment. So I am adding an answer.
Your code tells me that it would insert a record for the first time and after that it wouldn't insert at all. Is this the case?
I am saying this because. When the page loads for the first time, value of both
ViewState
and
Session
's "update" key gets the same value.
Now when you click the button, Page_Load code is not executed as it is inside
Page.IsPostBack
. Now
Button1_Click
is fired which will execute
AddEmployee
and
Session("update")= Server.URLEncode(System.DateTime.Now.ToString())
will update the value of session.
Now, lets see what happens when you click the button again for entering a new record.
Firstly, the sequence of execution,
Page_Load
then
Button1_Click
and then
Page_PreRender
.
Now, code within
Page_Load
is not executed (
Page.IsPostback
is true)
Button1_Click
is fired. It would not go inside the loop as Session("update") is not equal to ViewState("update").
Which is what you don't want.
Please let me know if this is what is happening.