dotnet: declare a linkbutton to make it invisible

<asp:datalist id="mydatalist" runat="server" OnDeleteCommand="procedures_dataset" OnUpdateCommand="procedures_dataset"
                        OnEditCommand="procedures_dataset" DataKeyField="Id">
      <ItemTemplate>
      <table>
      <tr>
      <td><%#Container.DataItem("GeboorteDatum")%></td>
      <td>
      <asp:Linkbutton CommandName="Edit" Runat="server" text="Edit"></asp:Linkbutton>
        <asp:Linkbutton id="DeleteButton" CommandName="Delete" Runat="server" text="Delete"></asp:Linkbutton>
      </td>
      </tr>


hi,
I need to declare in the code behind the linkbutton=DeleteButton
  Protected WithEvents DeleteButton As ??????

bcs i need to control this button in the code behind to make it sometimes invisible
  DeleteButton.Visible = False
tks

karel
LVL 6
karel_jespersAsked:
Who is Participating?
 
jitgangulyConnect With a Mentor Commented:
Then there must be something else. Can you please post your full code with the latest changes you made
0
 
jitgangulyCommented:
private void DeleteButton_Click(object sender, System.EventArgs e)
{
// your code here

}
0
 
jitgangulyCommented:
and you can also use Visible=false in HTML itself
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Mike_MetroCommented:
<asp:Linkbutton CommandName="Edit" Runat="server" text="Edit" Visible="False"></asp:Linkbutton>
0
 
karel_jespersAuthor Commented:
tks for you help

but i need to make the linkbutton invisible in the code behind using the visual basic behind the html

to do that i must declare the link button in the basic code *.aspx.vb source

i must declare it therefore

Protected WithEvents DeleteButton As ??????  <=================

how must i declare to access a link button within a datalist

tks
karel
0
 
jitgangulyCommented:
Put this in on Page_Load and see

DeleteButton.Visible = False
0
 
karel_jespersAuthor Commented:
tks for help,
i added the line to the page_load but then i receive an error msg telling met
DeleteButton is not declared
and this is where i m looking for
Protected WithEvents DeleteButton As ??????  <=how must i declare the linkbutton inside a datalist

karel

0
 
jitgangulyCommented:
Can I see your whoel code pls. HTML+Code behind
0
 
karel_jespersAuthor Commented:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="vb_InlezenWijzigenDataViaDataset.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <TITLE>WebForm1</TITLE>
      </HEAD>
      <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
      <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
      <meta content="JavaScript" name="vs_defaultClientScript">
      <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
      <form id="Form1" runat="server">
            <center><asp:checkboxlist id="check1" runat="server" OnSelectedIndexChanged="Check" TextAlign="Right" AutoPostBack="True">
                        <asp:ListItem checked="true">DATABASE => DATASET  klik hier na accept</asp:ListItem>
                        <asp:ListItem>Item 2</asp:ListItem>
                  </asp:checkboxlist><br>
                  <asp:label id="mess" runat="server"></asp:label><br>
                  <asp:datalist id="mydatalist" runat="server" OnDeleteCommand="procedures_dataset" OnUpdateCommand="procedures_dataset"
                        OnEditCommand="procedures_dataset" DataKeyField="Id">
                        <ItemTemplate>
                              <table>
                                    <tr>
                                          <td><%#Container.DataItem("Id")%></td>
                                          <td><%#Container.DataItem("Tekst")%></td>
                                          <td><%#Container.DataItem("Naam")%></td>
                                          <td><%#Container.DataItem("GeboorteDatum")%></td>
                                          <td>
                                                <asp:Linkbutton CommandName="Edit" Runat="server" text="Edit"></asp:Linkbutton>
                                                <asp:Linkbutton CommandName="Delete" Runat="server" text="Delete"></asp:Linkbutton>
                                          </td>
                                    </tr>
                              </table>
                        </ItemTemplate>
                        <EditItemTemplate>
                              <table>
                                    <tr>
                                          <td><%#Container.DataItem("Id")%></td>
                                          <td>
                                                <asp:Textbox runat="server" id="txtTekst" text='<%#Databinder.Eval(Container.DataItem, "Tekst") %>' >
                                                </asp:Textbox>
                                                <asp:Textbox runat="server" id="txtNaam" text='<%#Databinder.Eval(Container.DataItem, "Naam") %>' >
                                                </asp:Textbox>
                                                <asp:Textbox runat="server" id="txtGeboorteDatum" text='<%#Databinder.Eval(Container.DataItem, "GeboorteDatum") %>' >
                                                </asp:Textbox>
                                          </td>
                                          <td>
                                                <asp:Linkbutton CommandName="Update" Runat="server" text="Update"></asp:Linkbutton></td>
                                    </tr>
                              </table>
                        </EditItemTemplate>
                  </asp:datalist><br>
                  <asp:linkbutton id="acceptbutton" Runat="server" text="Accept"></asp:linkbutton><br>
                  <asp:linkbutton id="cancelbutton" Runat="server" text="Cancel"></asp:linkbutton><br>
                  <asp:linkbutton id="insertbutton" Runat="server" text="Insert=Nieuw record toevoegen"></asp:linkbutton><br>
                  <br>
                  <A onclick="javascript:window.close()" href="#">EXIT</A>
            </center>
      </form>
</HTML>



code behind is very long


Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents mess As System.Web.UI.WebControls.Label
    Protected WithEvents mydatalist As System.Web.UI.WebControls.DataList
    Private conn As SqlConnection
    Private mydataadapter As SqlDataAdapter
    Protected WithEvents acceptbutton As System.Web.UI.WebControls.LinkButton
    Protected WithEvents insertbutton As System.Web.UI.WebControls.LinkButton
    Protected WithEvents cancelbutton As System.Web.UI.WebControls.LinkButton
    Private mydataset As DataSet
    Protected WithEvents check1 As System.Web.UI.WebControls.CheckBoxList

.....
0
 
jitgangulyCommented:
Where is deletebutton declared ?
Is it something like

<asp:linkbutton id="deletetbutton" Runat="server" text="Accept"></asp:linkbutton><br>


you speak dutch ?
0
 
karel_jespersAuthor Commented:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="vb_InlezenWijzigenDataViaDataset.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <TITLE>WebForm1</TITLE>
      </HEAD>
      <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
      <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
      <meta content="JavaScript" name="vs_defaultClientScript">
      <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
      <form id="Form1" runat="server">
            <center><asp:checkboxlist id="check1" runat="server" OnSelectedIndexChanged="Check" TextAlign="Right" AutoPostBack="True">
                        <asp:ListItem checked="true">DATABASE => DATASET  klik hier na accept</asp:ListItem>
                        <asp:ListItem>Item 2</asp:ListItem>
                  </asp:checkboxlist><br>
                  <asp:label id="mess" runat="server"></asp:label><br>
                  <asp:datalist id="mydatalist" runat="server" OnDeleteCommand="procedures_dataset" OnUpdateCommand="procedures_dataset"
                        OnEditCommand="procedures_dataset" DataKeyField="Id">
                        <ItemTemplate>
                              <table>
                                    <tr>
                                          <td><%#Container.DataItem("Id")%></td>
                                          <td><%#Container.DataItem("Tekst")%></td>
                                          <td><%#Container.DataItem("Naam")%></td>
                                          <td><%#Container.DataItem("GeboorteDatum")%></td>
                                          <td>
                                                <asp:Linkbutton CommandName="Edit" Runat="server" text="Edit"></asp:Linkbutton>
                                                <asp:Linkbutton id="DeleteButton" CommandName="Delete" Runat="server" text="Delete"></asp:Linkbutton>
                                          </td>
                                    </tr>
                              </table>
                        </ItemTemplate>
                        <EditItemTemplate>
                              <table>
                                    <tr>
                                          <td><%#Container.DataItem("Id")%></td>
                                          <td>
                                                <asp:Textbox runat="server" id="txtTekst" text='<%#Databinder.Eval(Container.DataItem, "Tekst") %>' >
                                                </asp:Textbox>
                                                <asp:Textbox runat="server" id="txtNaam" text='<%#Databinder.Eval(Container.DataItem, "Naam") %>' >
                                                </asp:Textbox>
                                                <asp:Textbox runat="server" id="txtGeboorteDatum" text='<%#Databinder.Eval(Container.DataItem, "GeboorteDatum") %>' >
                                                </asp:Textbox>
                                          </td>
                                          <td>
                                                <asp:Linkbutton CommandName="Update" Runat="server" text="Update"></asp:Linkbutton></td>
                                    </tr>
                              </table>
                        </EditItemTemplate>
                  </asp:datalist><br>
                  <asp:linkbutton id="acceptbutton" Runat="server" text="Accept=Wegschrijven van wijzigingen"></asp:linkbutton><br>
                  <asp:linkbutton id="cancelbutton" Runat="server" text="Cancel=Wijzingen annuleren"></asp:linkbutton><br>
                  <asp:linkbutton id="insertbutton" Runat="server" text="Insert=Nieuw record toevoegen"></asp:linkbutton><br>
                  <br>
                  <A onclick="javascript:window.close()" href="#">EXIT</A>
            </center>
      </form>
</HTML>
0
 
karel_jespersAuthor Commented:
in this code , you find it, previous code was from  a wrong version
0
 
jitgangulyCommented:
I am lost here

This works perfectly in my machine

private void Page_Load(object sender, System.EventArgs e)
{
DeleteButton.Visible=False                        
}
0
 
karel_jespersAuthor Commented:
bsc i didnt entered a
   Protected WithEvents DeleteButton As System...
the basic code cannot work with the DeleteButton
I must declare it but dont know how

in your example did you put the html code the same
a linkbutton inside the itemtemplate of a datalist
0
 
jitgangulyCommented:
Back.Sorry got stuck yesterday. IS it solved yet ?

You have to declare like this

protected System.Web.UI.WebControls.Button Button1;

This is C#
I would get you VB
0
 
jitgangulyCommented:
VB would be

Protected WithEvents Deletebutton As System.Web.UI.WebControls.Button
0
 
karel_jespersAuthor Commented:
for one or another reason the linkbutton doesn't becomes unvisible

doesnt i have to put
Public WithEvents Deletebutton As System.Web.UI.WebControls.Button = New System.Web.UI.WebControls.Button



0
 
jitgangulyCommented:
? Didn;t  get u ?
I just hope you have the code in Page _Load

DeleteButton.Visible=False  

come to MSN IM, abhijitg is my id
0
 
karel_jespersAuthor Commented:
the code is there but apparently, the button stays visible
0
 
jitgangulyCommented:
A 'C' Grade ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.