-2

I have a page which is having the following

Some ddl's for Filter the data

  • A Submit button
  • A export Button
  • A GridView

In general We show/hide Export button if submit query results more than zero rows/ no rows

NOTE:

It is not only the case for one button but there would be more and i will have to check for the permission for every where i show /hide the buttons

For Example

Page_Load

showHideAsPerPermission(btnExport);


BtnSubmitClick()

if rows>0
    btnExport.Visible = true;
else
    btnExport.Visible = false;

But for the purpose of Permission

I want to set Export button visibility to true/false after BtnSubmit_click (or all controls events like selected index change, textChanged etc.) event has fired

A little Explanation of my problem

Say if you have permission to export then it only visible when rows>0 and if you don't have then it invisible even rows>0 but if i set the permission on page load and then i set exports visibility true for rows > 0 then it is visible even you don't have permission so is there any event which fires after control events

Is there any method which i can utilize for this purpose

I have read the following events and tried Page_Unload event which actually does nothing cause page is already rendered

So is there any method which could accomplish my task

enter image description here

Note:

As per my Knowledge there is no such Event so can i create a custom page event?

Community
  • 1
  • 1
Trikaldarshiii
  • 11,174
  • 16
  • 67
  • 95
  • After page_load button_click will called and i will there show/ hide export button – Trikaldarshiii Dec 15 '13 at 15:58
  • That's fine. You can set all visibilities in page_load and also in the click event. – MikeSmithDev Dec 15 '13 at 15:59
  • I don't want to set in both – Trikaldarshiii Dec 15 '13 at 16:01
  • You can set it in either place. – MikeSmithDev Dec 15 '13 at 16:01
  • there would be a lot of buttons like edit, export, print etc. – Trikaldarshiii Dec 15 '13 at 16:02
  • So that's three lines of code. You don't even need an `if` statement. Just say `btnExport.Visible = rows>0`. – MikeSmithDev Dec 15 '13 at 16:05
  • I am not even bothering lines of code but I am bothering of no of places where i would like to tackle with this and the major concern is the permission if user is permitted then and only then it should visible regardless the row count – Trikaldarshiii Dec 15 '13 at 16:06
  • Well, you apparently have to set the visibility on the initial Page_Load based on the number of rows. Then on postback (`BtnSubmit_click`) you need to change it again. I don't understand your question. I said where to tackle -- just do it in Page_Load (if it isn't a post-back). If you need to do something specific in `BtnSubmit_click` then yes you will have to have some code there too. – MikeSmithDev Dec 15 '13 at 16:08
  • Get rid of that big graphic and include some code if you are having a problem with your code. – MikeSmithDev Dec 15 '13 at 16:11
  • Its simple if you have permission to export then it only visible when rows>0 and if you don't have then it invisible even rows>0 but if i set the permission on page load and then i set exports visibility true for rows > 0 then it is visible even you don't have permission so is there any event which fires after controlevents – Trikaldarshiii Dec 15 '13 at 16:12
  • @MikeSmithDev As per my Knowledge there is no Such Event – Trikaldarshiii Dec 15 '13 at 16:15
  • You haven't explained why you need to re-set the visibility on `BtnSubmit_click`. Please clarify your question. It sounds like "I am setting the button visibility correctly and then later I'm setting it incorrectly." You set the visibility on Page_Load if it isn't a post back. If you need to change the visibility later based on an event (click, index change, etc), then you properly set it inside there. I recommend you just attempt it and if you have any issues, post them here. – MikeSmithDev Dec 15 '13 at 16:18
  • See I set first on Page_load as per permission and then as per row count but at this stage i should reset the permission after setting as per row count which actually i want to do in that event i was looking for so that i will use only that event not page_load so permission will automatically will be set – Trikaldarshiii Dec 15 '13 at 16:22
  • Remove the graphic. Include your code. State the problem with visibilities. We can't help fix your code if there is no code. – MikeSmithDev Dec 15 '13 at 16:26

1 Answers1

0

Just do it in Page_Load.

Keep in mind, on BtnSubmit_click, the page will post back, Page_Load is going to execute again (so you'll probably need something like if (!IsPostback)...), and then BtnSubmit_click.

MikeSmithDev
  • 15,731
  • 4
  • 58
  • 89