?
Solved

How to control the AutoPostBack

Posted on 2007-10-18
10
Medium Priority
?
313 Views
Last Modified: 2008-03-06
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
Comment
Question by:mrong
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:divinewind80
ID: 20100976
You can check its visibility on the OnLoad event.  This way you can change the autopostback property if needed to false.
0
 

Author Comment

by:mrong
ID: 20100990
Could you please provide some sample code?
Thanks.
0
 
LVL 9

Expert Comment

by:divinewind80
ID: 20101031
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:mrong
ID: 20101110
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
 

Author Comment

by:mrong
ID: 20101404
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
 
LVL 9

Expert Comment

by:divinewind80
ID: 20101498
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
 

Author Comment

by:mrong
ID: 20101536
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
 

Author Comment

by:mrong
ID: 20101543
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
 
LVL 9

Accepted Solution

by:
divinewind80 earned 240 total points
ID: 20102686
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question