Solved

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

Posted on 2008-10-01
7
883 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Introduction (All good things must come to an end (http://en.wikipedia.org/wiki/All_Good_Things...))The original MySQL API (http://php.net/manual/en/book.mysql.php) has gone away, deprecated by PHP in Version 5.5, and removed from PHP in all current…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
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.

710 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