RCDAWebmaster
RCDAWebmaster

Reputation: 325

isPostback always returns false, even after posting back to the page

I have a vb.net page and on the page is a select box. When someone changes the selected item in the select box, some fancy javascript fires to put the selected value into a hidden form at the bottom of the page and submit that value back to the page.

<script>
 function cat(inForm){
        document.getElementById('Cat_ID').value = inForm.Catechumen_ID.value;
        document.getElementById('passCat').submit();
    }
</script>

Based upon this postback, I want to update the page to be based upon the value that was posted back to the page.

I added:

<script>

    alert("postback: <%= Page.IsPostBack = true %>" );
</script>

to the page and it alerts me that isPostback is false on initial load and after postback. why?

Upvotes: 0

Views: 268

Answers (2)

RCDAWebmaster
RCDAWebmaster

Reputation: 325

After thinking about it, why ask if isPostBack = true, when I can simply ask if the variable I posted has a value.

if request.form("cat_ID") <> "" then
  'isPostBack
else
  'not isPostBack
end if

Upvotes: 1

Nader Hashemi
Nader Hashemi

Reputation: 21

You normally use 'is post back' page property in page load event for data bindings for controls such as grid view that use view state.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles Me.Load

   If Not Page.IsPostBack Then

    ' More coding will go here.
    '--------------------------
   End If

Upvotes: 0

Related Questions