Monday, August 2, 2010

Disabling Action on Specific Pages

Q.  How can I disable the New and Delete button on any particular page.

A.

Consider using WhenHRef property of data controller actions. Open the data controller definition in Designer, select Actions tab and activate the action. The action property WhenHRef must represent a valid regular expression.

For example, If you want to use New and Delete actions on pages ~/Pages/Page1.aspx and ~/Pages/Page2.aspx only then the following syntax will work.

Page1|Page2

The assumption is made that the same data controller is present on both pages. You can use any valid regular expression to create a URL test.  The expression will be tested against the URL in the web browser address box. A more precise and complex expression may look as the one below:

/Pages/Page(1|2)\.aspx

If there are other pages that use the same data controller and you want to prevent New and Delete actions from displaying on Page1 and Page2 but have them available on all other pages then we recommend to use an extension to regular expression syntax. Simply put "false:" in front of your expression:

false:Page1|Page2

The prefix in the example above is not a part of regular expression definition and is used to make it easier writing negative regular expression then would have been required otherwise.

2 comments:

Anton said...

That is useful. And that is the kind of thing I think illustrates the need for some kind of decent documentation for code on time, explaining what we can and cannot do.

Seriously, code on time is great, but the fact that we have to scrounge around or ask someone for every little thing we need to do differently (with the added time of waiting for the replies) is irritating, to say the least, and, in my opinion, a huge downside. If you could compile a comprehensive document explaining the API to the generated classes and the syntax to use in the designer I'm sure you would have a great deal of new subscriptions and more faithful customers.

Customer Service said...

Anton, the product is growing rapidly. We realize a need for better documentation and working diligently on offering new tutorials at http://codeontime.com/tutorials.aspx.

You can find more about Code OnTime Generator, Data Aquarium Framework, and other great products here.


© 2010 Code OnTime LLC. Intelligent code generation software for ASP.NET. Visit us at http://codeontime.com