nelek
nelek

Reputation: 4322

Populating Repeater with disabled ViewState (asp.net/vb.net)

I have some code bellow :

Protected Sub Page_Load(....
 If Not IsPostBack Then 
   Session("isloaded") = True
   PopulateData()
 End If
 If Session("isloaded") = True Then Session("isloaded") = False Else PopulateData()
End Sub

Private Sub btnEditCancel_Click(....
 Session("isloaded") = False
End Sub

Private Sub btnEditSave_Click(...
 Session("isloaded") = True
 PopulateData()
End Sub

Because, when I click btnEditSave Repeater is populated. But, when I click btnEditCancel Repeater isn't populated. PopulateData() is subroutine for populating asp:Repeater using asp:SqlDataSource. btw. EnableViewState in asp:Repeater is disabled.

How to solve this problem?

Is it possible that Page_Load fire first and after that Session("isloaded") is set to False?

p.s. sorry for my weak english, I hope you, people, will understand point of question.

Upvotes: 0

Views: 84

Answers (1)

Rajesh
Rajesh

Reputation: 1620

First in your code in the btnEditSave_Click event you are making Session("isloaded") = True then if you click btnEditCancel button in the Page load because its Postback it will execute only

 If Session("isloaded") = True Then Session("isloaded") = False Else PopulateData()

in that it will only execute IF part as you are making Session("isloaded") = True in btnEditSave_Click event it will not call PopulateData() in ELSE part

Make a Change in btnEditCancel_Click event like

Private Sub btnEditCancel_Click(....
 If Session("isloaded") = False Then PopulateData()
End Sub

Upvotes: 1

Related Questions