There are a variety of "standard" techniques for this.
The basic setup is: conditionally display some content on the page.
The condition is app dependent. I just assume there's a Property that will
return a bool indicating whether or not the component should be displayed.
Most any html can 'runat' the server. All Web Controls can, of course. Any
server-based html block can be set Visible='false' or can be put inside a
asp
laceHolder or asp
anel that in-turn can have it's Visible attribute
set to false or true for conditional display of any contents.
Then you got 2 ways to go for setting that Visible attribute: data-binding
or programmatically setting the control.
Here are those 2:
The programmatic approach is trivial, just put the logic in any old part of
the code that participates in page rendering. If you will know whether to
display when the page is loaded (as opposed to after a post-back) then the
logic can go in Page_Load:
<asp
anel id="someConditionalDisplay" Runat="server">Show this or
don't!</asp
anel>
Then in the code-behind:
public class MyPageOrUserControlClass
{
protected System.Web.UI.WebControls.Panel someConditionalDisplay;
private void Page_Load(object sender, System.EventArgs e)
{
someConditionalDisplay.Visible = false; // or true, or ...
}
// assume standard VS "wiring": that Page_Load has been added to the page's
OnLoad event call-backs.
}
If you won't know whether to display or not at page load you can set the
Visible flag later -- either in the particular event (e.g., button click)
post/call back, or by overriding the OnPreRender() method.
Note that, like all ASP.Net server controls you gotta set the control's ID
attribute to map to the name of a variable in the code behind.
As for data-binding it's pretty similar:
<asp
anel id="someConditionalDisplay" Runat="server" Visible='<%#
ShowConditionalDisplay %>'>Show this or don't!</asp
anel>
Then in the code-behind:
public class MyPageOrUserControlClass
{
protected System.Web.UI.WebControls.Panel someConditionalDisplay;
protected bool ShowConditionalDisplay
{
get { return false; // or true, or ... check if the user is
logged in ...}
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack) {
this.DataBind();
}
}
// assume standard VS "wiring": that Page_Load has been added to the page's
OnLoad event call-backs.
}
The short of it is, the gid is part of your app's logic and is not somethin
that ASP.net will check for. You need to set the control's ID. Note,
another approach is if you're writing your own controls and are willing to
make them closely bound to the app context in which they will be used the
control can have its own logic: checks it's gid, then looks at who's logged
into the app and then set itself visible or not accordingly.
Hope that helps,
Ezra E.