Solved

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

Posted on 2008-10-01
7
880 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
Independent Software Vendors: 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!

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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 …
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
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.

685 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