Solved

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

Posted on 2008-10-01
7
872 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

791 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