Solved

dotnet: declare a linkbutton to make it invisible

Posted on 2004-09-22
21
482 Views
Last Modified: 2012-05-05
<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
0
Comment
Question by:karel_jespers
  • 11
  • 8
21 Comments
 
LVL 20

Expert Comment

by:jitganguly
ID: 12123066
private void DeleteButton_Click(object sender, System.EventArgs e)
{
// your code here

}
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 12123102
and you can also use Visible=false in HTML itself
0
 
LVL 6

Expert Comment

by:Mike_Metro
ID: 12123222
<asp:Linkbutton CommandName="Edit" Runat="server" text="Edit" Visible="False"></asp:Linkbutton>
0
 
LVL 6

Author Comment

by:karel_jespers
ID: 12125118
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
 
LVL 20

Expert Comment

by:jitganguly
ID: 12125389
Put this in on Page_Load and see

DeleteButton.Visible = False
0
 
LVL 6

Author Comment

by:karel_jespers
ID: 12131325
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
 
LVL 20

Expert Comment

by:jitganguly
ID: 12132780
Can I see your whoel code pls. HTML+Code behind
0
 
LVL 6

Author Comment

by:karel_jespers
ID: 12134554
<%@ 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
 
LVL 20

Expert Comment

by:jitganguly
ID: 12134684
Where is deletebutton declared ?
Is it something like

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


you speak dutch ?
0
 
LVL 6

Author Comment

by:karel_jespers
ID: 12135715
<%@ 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 6

Author Comment

by:karel_jespers
ID: 12135729
in this code , you find it, previous code was from  a wrong version
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 12135751
I am lost here

This works perfectly in my machine

private void Page_Load(object sender, System.EventArgs e)
{
DeleteButton.Visible=False                        
}
0
 
LVL 6

Author Comment

by:karel_jespers
ID: 12135867
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
 
LVL 20

Expert Comment

by:jitganguly
ID: 12143112
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
 
LVL 20

Expert Comment

by:jitganguly
ID: 12143129
VB would be

Protected WithEvents Deletebutton As System.Web.UI.WebControls.Button
0
 
LVL 6

Author Comment

by:karel_jespers
ID: 12143842
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
 
LVL 20

Expert Comment

by:jitganguly
ID: 12143869
? 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
 
LVL 6

Author Comment

by:karel_jespers
ID: 12155997
the code is there but apparently, the button stays visible
0
 
LVL 20

Accepted Solution

by:
jitganguly earned 500 total points
ID: 12159936
Then there must be something else. Can you please post your full code with the latest changes you made
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 12717218
A 'C' Grade ?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now