locked
How do i do this in Vb.net RRS feed

  • Question

  • User-2064830606 posted

    The code below is done in C#. I just need to do this in VB.net, It involved  operator overloading. Please help

     protected void ChangeAppearanceButton_Click(object sender, EventArgs e)

    {

    this.TestPanel.Visible = this.TestPanel.Visible ? false : true;

    }

     

    Monday, April 21, 2008 9:16 AM

Answers

  • User1693635062 posted

    I'm not sure if you're trying to inclode both lines of code in your program but if you leave your toggle as is in your page load it will have a negative effect.

    solution to your page load code

    If Not IsPostBack Then

    code....

    end if

    that will only execute the code... part once and won't when the page simply posts back from clicking a button or control meant to activate a postback

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 21, 2008 2:11 PM

All replies

  • User-1995538749 posted

    If you're just wanting to toggle the Visible state of the control, then how about:

    Me.TestPanel.Visible = Not Me.TestPanel.Visible

    Monday, April 21, 2008 9:21 AM
  • User-2064830606 posted

    It works, Thanks a lot but for some reason in design view, while clicking on the link button, the code points to page load instead of

    ChangeAppearanceButton_Click  . Woks fineon adding your line of code here

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Me.TestPanel.Visible = Not Me.TestPanel.Visible

    End Sub

    But does not work here

     Protected Sub ChangeAppearanceButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ChangeAppearanceButton.Click

    Me.TestPanel.Visible = Not Me.TestPanel.Visible

    End Sub

     

    Monday, April 21, 2008 10:01 AM
  • User-2064830606 posted

    Here is also the page code 

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head id="Head1" runat="server">

    <title>Untitled Page</title>

    </head>

    <script language= "javascript" type= "text/javascript" >

    function changeColor(box)

    {

    document.all.form1.TextBox2.style.background =
    '#00CC40';

     

     

    }

    </script>

     

    <body>

    <form id="form1" runat="server">

    <div>

     

    <asp:panel id="TestPanel" runat="server" Height="171px" Width="926px">

    <h2> An example HTML segment that is going to disappear </h2>

     

    &nbsp;

     

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <asp:Label ID="Label2" runat="server" Text="VFR Primary: "></asp:Label>

     

    &nbsp;<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

    &nbsp;<br />

    <br />

     

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

     

    <asp:Label ID="Label1" runat="server" Text="IFR Overs: "></asp:Label>

    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;

     

    <asp:Label ID="Label3" runat="server"

    Text="IFR/SVFR/PVFR Less15:"></asp:Label>

    &nbsp;<asp:TextBox ID="TextBox4" runat="server" Width="130px"></asp:TextBox>

    <br />

    <br />

     

    &nbsp; <asp:Label ID="Label4" runat="server"

    Text="IFR/SVFR/PVFR Primary: "></asp:Label>

     

    <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>

     

    &nbsp;

     

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <asp:Label ID="Label5" runat="server" Text="VFR Primary:"></asp:Label>

     

    &nbsp;&nbsp;<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>

    &nbsp;<br />

    <br />

     

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

     

    <asp:Label ID="Label6" runat="server" Text="IFR Overs: "></asp:Label>

    <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;

     

    <asp:Label ID="Label7" runat="server"

    Text="IFR/SVFR/PVFR Less15: "></asp:Label>

    <asp:TextBox ID="TextBox8" runat="server" Height="22px" Width="129px"></asp:TextBox>

    <br />

    <br />

     

    &nbsp; <asp:Label ID="Label8" runat="server"

    Text="IFR/SVFR/PVFR Primary: "></asp:Label>

     

    <asp:TextBox ID="TextBox9" runat="server"></asp:TextBox>

     

    &nbsp;

     

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <asp:Label ID="Label9" runat="server" Text="VFR Primary:"></asp:Label>

     

    &nbsp;<asp:TextBox ID="TextBox10" runat="server" Width="130px"></asp:TextBox>

    &nbsp;<br />

    <br />

     

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

     

    <asp:Label ID="Label10" runat="server" Text="IFR Overs: "></asp:Label>

    <asp:TextBox ID="TextBox11" runat="server"></asp:TextBox>

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;

     

    <asp:Label ID="Label11" runat="server"

    Text="IFR/SVFR/PVFR Less15: "></asp:Label>

    <asp:TextBox ID="TextBox12" runat="server" Width="129px"></asp:TextBox>

    <br />

    <br />

    <br />

     

    <br />

    <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <asp:Button ID="Button1" runat="server" Text="Add" Width="60px" />

    &nbsp;

    <asp:Button ID="Button2" runat="server" Text="Delete" Width="62px" />

    &nbsp;&nbsp;

    <asp:Button ID="Button3" runat="server" Text="Update" />

    &nbsp;&nbsp;

    <asp:Button ID="Button4" runat="server" Text="Cancel" />

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <br />

     

    </asp:panel>

    </div>

    <asp:LinkButton id="ChangeAppearanceButton" runat="server"

    onclick="ChangeAppearanceButton_Click">

    Edit Form

    </asp:LinkButton>

    <br />

    <br />

    </form>

    </body>

    </html>

    Monday, April 21, 2008 10:03 AM
  • User1693635062 posted

    I'm not sure if you're trying to inclode both lines of code in your program but if you leave your toggle as is in your page load it will have a negative effect.

    solution to your page load code

    If Not IsPostBack Then

    code....

    end if

    that will only execute the code... part once and won't when the page simply posts back from clicking a button or control meant to activate a postback

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 21, 2008 2:11 PM
  • User-2064830606 posted
    Thanks, It works fine
    Tuesday, April 22, 2008 9:40 AM