• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

How to control the AutoPostBack

Greeting,
I use checkbox the control one button. I have repeater on my asp.net form and it has a checkbox field.  if any checkbox being check marked I make the button1 visible ortherwise it stays invisible.

Here is the question. I set AutoPostBack=true for that checkbox field. But I don't want to PostBack to the page if button1 is already visible. How to add a condition-checking?

Thanks.
0
mrong
Asked:
mrong
  • 5
  • 4
1 Solution
 
divinewind80Commented:
You can check its visibility on the OnLoad event.  This way you can change the autopostback property if needed to false.
0
 
mrongAuthor Commented:
Could you please provide some sample code?
Thanks.
0
 
divinewind80Commented:
Sure.  Let's say, for example, you would like to do it on the Checkbox's load event (although the page's event might be better), you could set the OnLoad event in the checkbox like so:  OnLoad="cb1_load".  Then, in code behind, you could do the following:

Public sub cb1_load(sender as object, e as system.eventargs)
if button1.visible = true then
cb1.autopostback = false
else
cb1.autopostback = true
end if
End sub

By using this, you shouldn't have to have the autopostback set in the checkbox control itself, rather you would handle it in the code-behind.

Does that help?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
mrongAuthor Commented:
is the cb1 the name of the checkbox field? I replaced it with the name of my checkbox field and it didn't work.

 Thanks.
0
 
mrongAuthor Commented:
I have the following. But the page  postback to itself twice instead of 1 when the button is visible. Is it caused by alternatingitemtemplate? Thanks.

Public Sub cb1_load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim tmpCheck As CheckBox = sender
        If UpdateButton.Visible = True Then
            tmpCheck.AutoPostBack = False
        Else
            tmpCheck.AutoPostBack = True
        End If
    End Sub
0
 
divinewind80Commented:
Yes, the cb1 was the name of the checkbox.

Concerning the double postback... are you meaning it will postback and then immediately, without any other action on the user's part, postback again?
0
 
mrongAuthor Commented:
I mean the page got postback when they click on the checkbox the first two times. After that, it won't postback anymore.

below is what I have. I have this code in both the itemtemplate and alternatingitemtemplete.

<td> <asp:CheckBox id="closeCase" ToolTip = '<%# DataBinder.Eval(container.DataItem, "proposal") %>' runat="server" onload="cb1_load" OnCheckedChanged="SomeSub" ></asp:CheckBox>
0
 
mrongAuthor Commented:
Below is my SomeSub.

 Protected Sub SomeSub(ByVal s As Object, ByVal e As EventArgs)
        Dim tmpCheck As Checkbox = s
        If tmpCheck.Checked = True Then
            UpdateButton.Visible = True

        Else

        End If

    End Sub
0
 
divinewind80Commented:
Just out of curiosity, try adding the AutoPostBack changes into your SomeSub... like so:

 Protected Sub SomeSub(ByVal s As Object, ByVal e As EventArgs)
        Dim tmpCheck As Checkbox = s
        If tmpCheck.Checked = True Then
            UpdateButton.Visible = True
tmpCheck.AutoPostBack = false
        Else
tmpCheck.AutoPostBack = true
        End If

    End Sub

Also, for the sake of this attempt, try removing the "OnLoad" event...

Let me know if this works.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now