Solved

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

Posted on 2008-10-01
7
898 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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 …
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.

636 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