Solved

Why does my PreRender CancelButton.Visible = False does not work after a post back?

Posted on 2008-10-01
7
855 Views
Last Modified: 2011-10-19
Hello,

The CancelButton.Visible = False in the code I attach does not work after a post back.

Could you tell me why?

I've checked in debug mode and the property is being set at all times! (When I hover the mouse over I can see that CancelButton.Visible = False) But it only works the first time.

The reason the form reloads is because every time the insert fails it shows the exception message.

Thanks in advance.


Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
 

        If String.IsNullOrEmpty(Page.Request.QueryString("UserName")) Then
 

            UserDetailsView.ChangeMode(DetailsViewMode.Insert)
 

            Dim CancelButton As Control = UserDetailsView.FindControl("CancelButton")

            CancelButton.Visible = False

        End If
 

    End Sub

Open in new window

0
Comment
Question by:richardhaeger
  • 4
  • 3
7 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22624207
see you yourself gave the answer

see as per your comment this line is giving you error
UserDetailsView.ChangeMode(DetailsViewMode.Insert) so after exception application doesn't execute next line and that is why setting is not affected ...

so here you have 2 option

1. remove that line from that event or change the position of code
2. use try catch block inside that condition and put
    Dim CancelButton As Control = UserDetailsView.FindControl("CancelButton")
            CancelButton.Visible = False
above line in finally block
0
 

Author Comment

by:richardhaeger
ID: 22626539
Hello BondinASP,

Sorry but it seems I did not express myself correctly (English is not my native language).

Here are some pictures to better explain the mystery. The description on each picture describes the process.

Thanks again for any help you can provide.



01.gif
02.gif
03.gif
04.gif
05.gif
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22636250
I understood correctly ... can you please test this

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
 
        If String.IsNullOrEmpty(Page.Request.QueryString("UserName")) Then
 
                      Dim CancelButton As Control = UserDetailsView.FindControl("CancelButton")
            CancelButton.Visible = False
  UserDetailsView.ChangeMode(DetailsViewMode.Insert)
 

        End If
 
    End Sub
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:richardhaeger
ID: 22637438
Hello again BondinASP,

Thanks but this is what I got after trying your suggestion.

I believe it is because the cancel button is only present in the InsertItemTemplate, so only after switching to that mode the FindControl works.

Thanks anyway. Any more ideas? Have you seen the code in the original screen shots I posted?

06.gif
0
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 500 total points
ID: 22644490
use this method to set the cancel button value  

Protected Sub DetailsView1_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.PreRender
    {
        if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
        {
             Dim CancelButton As Control = UserDetailsView.FindControl("CancelButton")
            CancelButton.Visible = False
        }
    }
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22644494
that code is mixed of vb.net and C# for If  condition : (
0
 

Author Closing Comment

by:richardhaeger
ID: 31502206
Moving the CancelButton code to the DetailsView PreRender event did the trick. Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now