conditionally create asp:button

  • Thread starter Thread starter Tim Wallace
  • Start date Start date
T

Tim Wallace

I have an ascx file in which I want to sometimes create an asp:button
control based on a given value. Nothing I've tried has worked. How can I
accomplish this task?

Tim
 
You could use a placeholder, and then create the button + add it to the
placeholder's controls. Or you could always create the button, and just set
its Visible property.


--
Pete
====
Audio compression components, DIB graphics controls, FastStrings
http://www.droopyeyes.com

Read or write articles on just about anything
http://www.HowToDoThings.com
 
Thank you for your reply.

I don't know how to accomplish the placeholder trick, or even what you mean,
being new to ASP.Net.

I attempted to do the Visible trick, but it didn't want to work. Here is a
what I did as part of my table:

<td>
<br>
<asp:Button id=register name=register runat=server Text=register
CausesValidation=False OnClick=register_Click></asp:Button>
<% if( TTUser.UsersExist() == 0 )
{
register.Visible = false;
}
%>

I know the function is being called and returning a zero. I don't get any
errors, but the button stays visible. Any thoughts?

Tim
 
The visible trick is the most straightfoward. Try:

<asp:button id="register" runat="server" text="register"
CausesValidation=False OnClick="register_Click" />
<script runat="server" language="c#">
public void Page_Load(){
if (TTUser.UserExist() == 0){
register.Visible = false;
}
}
</script>
 
Thanks, Karl. I didn't even think about adding a Page_Load on the ascx (in
fact, I didn't think I could). Works fine.

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top