Compiler Error Message ASP.NET - c#

When trying to run my ASP.NET program i am getting this error message below:
Compiler Error Message: CS1061: 'ASP.about_aspx' does not contain a definition for 'btnRunReports_Click' and no extension method 'btnRunReports_Click' accepting a first argument of type 'ASP.about_aspx' could be found (are you missing a using directive or an assembly reference?)
Line 18 below seems to be the problem but i have no idea why.
Line 16: </p>
Line 17:
Line 18: <asp:Button ID="btnRunReports" runat="server" Text="Run Reports" onclick="btnRunReports_Click" />
Line 19:
Line 20: <p><asp:Button ID="IdSort" runat="server" Text="Sort" onclick="IdSort_Click" />
On the run reports button i have this following code:
protected void btnRunReports_Click(object sender, EventArgs e)
{
RunReport();
}
and then
public void RunReport()
{
Application.Lock();
// lb1 = (SaleList)Application["SaleList"];
TextReportGenerator trg = new TextReportGenerator(saleList);
trg.GenerateAllReport("report.txt");
Application.UnLock();
}
i have no idea how to fix this error, i have no errors in the .cs just on that line 18, some guidance would be much appreciated.
This is the About.aspx.cs
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Antiques;
using AntiqueSale;
namespace Antiques
{
public partial class About : System.Web.UI.Page, ISaleManagerUI
{
SaleList saleList;
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!ReferenceEquals(null, Session["ID"]))
{
Sale sale = new Sale((string)Session["ID"], (DateTime)Session["Date"], (string)Session["Location"], (double)Session["Picth Cost"], (int)Session["Num Pitches"],
(bool)Session["Charity"], (string)Session["Charity Name"], (bool)Session["Catering"]);
saleList = (SaleList)Application["SaleList"];
saleList.addSale(sale);
Application["SaleList"] = saleList;
UpdateListbox();
}
}
catch (DuplicateIdException)
{
UpdateListbox();
}
lblerror.Text = null;
}
public void LoadData()
{
try
{
Application.Lock();
SerializeFileHandler sr = new SerializeFileHandler();
Application["Antiques Sale"] = sr.ReadSaleListFromFile("data.dat");
UpdateListbox();
Application.UnLock();
}
catch (FileNotFoundException)
{
lblerror.Text = "Error: Not found, must save first";
}
}
protected void Load_Click(object sender, EventArgs e)
{
LoadData();
}
public void AddData()
{
var response = base.Response;
response.Redirect("Default.aspx", true);
}
protected void btnAddBox_Click(object sender, EventArgs e)
{
AddData();
}
public void getSale()
{
}
public void UpdateListbox()
{
Application.Lock();
lb1.Items.Clear();
saleList = (SaleList)Application["SaleList"];
for (int i = 0; i < saleList.Count(); i++)
{
// ListItem lst1 = new ListItem(lb1.saleList(i).ToString(), i.ToString());
// lst1.Items.Add(lb1);
}
Application.UnLock();
}
protected void lb1_Init(object sender, EventArgs e)
{
UpdateListbox();
}
protected void Delete_Click(object sender, EventArgs e)
{
while (lb1.SelectedIndex != -1)
{
ListItem mySelectedItem = (from ListItem li in lb1.Items where li.Selected == true select li).First();
lb1.Items.Remove(mySelectedItem);
}
}
protected void lb1_SelectedIndexChanged(object sender, EventArgs e)
{
}
public void SaveData()
{
saleList = (SaleList)Application["SaleList"];
if (saleList.Count() != 0)
{
Application.Lock();
SerializeFileHandler sr = new SerializeFileHandler();
sr.WriteSaleListToFile((SaleList)Application["SaleList"], "data.dat");
Application.UnLock();
}
else
{
lblerror.Text = "Error: You need to enter data into the list";
}
}
protected void Save_Click(object sender, EventArgs e)
{
SaveData();
}
protected void IdSort_Click(object sender, EventArgs e)
{
SortData();
}
public void SortData()
{
// var item = lb1.getItem(0);
// var index = item.get_index();
// lb1.reorderItem(item, index - 1);
}
public void RunReport()
{
Application.Lock();
// lb1 = (SaleList)Application["SaleList"];
TextReportGenerator trg = new TextReportGenerator(saleList);
trg.GenerateAllReport("report.txt");
Application.UnLock();
}
protected void btnRunReports_Click(object sender, EventArgs e)
{
RunReport();
}
}
}
`

Your Page Directive is wrong. It needs to be something like this:
<%# Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Antiques.About.aspx.cs" Inherits="Antiques.About" %>

Related

Saving Radio Button State

I want to save radio button state and select the radio button again on reloading the page. I have written the following code but it is not working:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Question_1 : System.Web.UI.Page
{
public int index;
public bool flag = false;
protected void Page_Load(object sender, EventArgs e)
{
if(flag)
{
index = (int)Session["index"];
if (index == 5)
{
totallyagree.Checked = true;
}
else if (index == 4)
{
agree.Checked = true;
}
}
}
protected void next_Click(object sender, EventArgs e)
{
flag=true;
if (totallyagree.Checked)
{
Session["index"] = 5;
}
else if (agree.Checked)
{
Session["index"] = 4;
}
Response.Redirect("Question 2.aspx");
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
//Session["index"] = RadioButtonList1.SelectedIndex;
}
}
Please help me with this issue.
did you try IsPostBack ?
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
index = (int)Session["index"];
if (index == 5)
{
totallyagree.Checked = true;
}
else if (index == 4)
{
agree.Checked = true;
}
}
}

imgCheck.ImageUrl = "/images/Blank.jpg"; wont work

Title explains it all. I am using this code at the top. It works. But you will see my comments at the bottom where it does not do anything. Everything else in the section works, just not that last line.
for testing, I created a separate button with the same line, it worked, but In the text changed handler for that specific text box, it just doesn't do anything.
thanks for the help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Visitor_Tracking
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//if (double.Pharse txtboxVisitorCode.TextChanged += )
{
txtboxVisitorCode.Focus();
imgCheck.ImageUrl = "/images/Blank.jpg";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
imgCheck.ImageUrl = "/images/GreenCheck.jpg";
}
protected void txtboxVisitorCode_TextChanged(object sender, EventArgs e)
{
if (txtboxVisitorCode.Text == "1234")
{
imgCheck.ImageUrl = "/images/GreenCheck.jpg";
lblPlate.Visible = true;
txtboxPlate.Visible = true;
btnPlate.Visible = true;
txtboxPlate.Focus();
}
else
{
imgCheck.ImageUrl = "/images/RedX.jpg";
txtboxVisitorCode.Text = "";
}
}
protected void txtboxPlate_TextChanged(object sender, EventArgs e)
{
lblPlate.Visible = false;
txtboxPlate.Visible = false;
txtboxPlate.Text = "";
txtboxVisitorCode.Text = "";
btnPlate.Visible = false;
btnPlate.Visible = false;
//
//
//
// this line does nothing
imgCheck.ImageUrl = "/images/Blank.jpg";
//
//
}
}
}

c# invokeMember click won't work

So I load a webpage, that has this in its html code:
<input style="margin-left: 140px;" name="e43X45asfaw4ybrZ34fi879234tg3e4eex" type="submit" id="submit" value="BegÄ kriminaliteten!" onmouseover="$('#ggg').fadeIn().delay(3000).fadeOut();">
and I use this to click it:
object o = webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("e43X45asfaw4ybrZ34fi879234tg3e4eex")[0].InvokeMember("click");
if (o != null)
{
MessageBox.Show("It worked!");
}
else
{
MessageBox.Show("It didnt work!");
}
and that code always leave it didn't work as well it didn't do anything to the webpage.
Here is my full code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MafiaspilletRankeBot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.Navigate("mafiaspillet.no");
webBrowser1.ScriptErrorsSuppressed = true;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
timer1.Enabled = true;
timer1.Interval = 15000;
}
catch {
timer1.Enabled = false;
MessageBox.Show("Timer error", "Looks like there a error");
}
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
timerun.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("brukernavn")[0].SetAttribute("value", textBox1.Text);
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("passord")[0].SetAttribute("value", textBox2.Text);
webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("login_buton")[0].InvokeMember("click");
timer2.Enabled = true;
timer2.Interval = 15000;
timer1.Enabled = false;
}
private void timer2_Tick(object sender, EventArgs e)
{
webBrowser1.Navigate("http://mafiaspillet.no/kriminalitet3.php");
timer3.Enabled = true;
timer3.Interval = 15000;
timer2.Enabled = false;
}
private void timer3_Tick(object sender, EventArgs e)
{
object o = webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("e43X45asfaw4ybrZ34fi879234tg3e4eex")[0].InvokeMember("click");
if (o != null)
{
MessageBox.Show("It worked!");
}
else
{
MessageBox.Show("It didnt work!");
}
MessageBox.Show("Bot finnished!", "YEEY!");
timer3.Enabled = false;
}
int i = 0;
private void runtime_Tick(object sender, EventArgs e)
{
i++;
timerun.Text = i.ToString() + " Sekunder";
}
}
}
So my problem is that the InvokeMember("click") doesn't work in my public void timer3_Tick.
It's like it can't do anything, but I can't find the problem :/
you need to processing in the function WebBrowserDocumentCompletedEventArgs
here full code
private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElementCollection inputCol = this.WebBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement el in inputCol)
{
if (el.GetAttribute("type").Equals("submit"))
{
el.InvokeMember("Click");
MessageBox.Show("It worked!");
}
}
}

"System.UnauthorizedAccessException" error when opening second serial port

i Need to open a second serialPort in my Visual C# program to read data from my arduino.
it already worked fine, but in the case you see below it does not work..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using CommandsPD4I;
namespace CSharpExample
{
public partial class CSharpExample : Form
{
public ComMotorCommands motor1;
public CSharpExample()
{
InitializeComponent();
motor1 = new ComMotorCommands();
motor1.SetSteps(Convert.ToInt32(numericSchritte.Value));
}
SerialPort arduino;
delegate void InvokeLB(string Data);
InvokeLB lbRecievedDelegate;
int xPos = 0;
private void StartBtn_Click(object sender, EventArgs e)
{
// Set comm settings for motor 1
motor1.SelectedPort = ComPortBox1.Text;
motor1.Baudrate = Convert.ToInt32(BaudrateBox1.Text);
// Set motor address
motor1.MotorAddresse = Convert.ToInt32(Motor1ID.Value);
// Set relative positioning mode
motor1.SetPositionType(1);
// Start travel profile
if (motor1.ErrorFlag)
{
StatusLabel1.Text = "Status 1: " + motor1.ErrorMessageString;
}
else
{
StatusLabel1.Text = "Status 1: OK";
}
}
private void StopBtn_Click(object sender, EventArgs e)
{
// Stop travel profile
motor1.StopTravelProfile();
}
private void timer1_Tick(object sender, EventArgs e)
{
lblPosition.Text = Convert.ToString(motor1.GetPosition());
lblStatus.Text = motor1.ErrorMessageString;
// this.chart1.Series["Kraft"].Points.AddXY(xPos, Convert.ToDouble(lblKraft.Text));
// xPos++;**strong text**
}
private void btnHoch_Click(object sender, EventArgs e)
{
motor1.SetDirection(0);
motor1.SetPositionType(1);
motor1.StartTravelProfile();
}
private void btnRunter_Click(object sender, EventArgs e)
{
motor1.SetDirection(1);
motor1.SetPositionType(1);
motor1.StartTravelProfile();
}
private void numericSchritte_ValueChanged(object sender, EventArgs e)
{
motor1.SetSteps(Convert.ToInt32(numericSchritte.Value));
}
private void numericGeschwindigkeit_ValueChanged(object sender, EventArgs e)
{
motor1.SetMaxFrequency(Convert.ToInt32(numericGeschwindigkeit.Value));
}
private void btnDiagramm_Click(object sender, EventArgs e)
{
if (timer1.Enabled)
{
timer1.Stop();
}
else
{
timer1.Start();
}
}
private void btnResetDiagramm_Click(object sender, EventArgs e)
{
this.chart1.Series["Kraft"].Points.Clear();
xPos = 0;
}
private void arduino_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string RecievedLine = " ";
while (RecievedLine != "")
{
RecievedLine = arduino.ReadLine();
lblKraft.Invoke(lbRecievedDelegate, new object[] { RecievedLine });
}
}
void Invokelabel1(string Data)
{
label1.Text = Data;
this.chart1.Series["Kraft"].Points.AddXY(xPos, Convert.ToDouble(lblKraft.Text));
xPos++;
}
private void btnArduino_Click(object sender, EventArgs e)
{
//Hier erstellen wir unseren Serialport und legen die Einstellungen fest
arduino = new SerialPort("COM7", 9600);
if (!arduino.IsOpen)
{
arduino.Open();
if (arduino.IsOpen)
{
lblArduino.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(200)))), ((int)(((byte)(0)))));
lblArduino.Text = "Verbunden mit " + arduino.PortName;
}
}
lbRecievedDelegate = new InvokeLB(Invokelabel1);
arduino.DataReceived += new SerialDataReceivedEventHandler(arduino_DataReceived); //DataRecieved Event abonnieren
}
}
}
When i leave out this:
motor1.SelectedPort = ComPortBox1.Text;
motor1.Baudrate = Convert.ToInt32(BaudrateBox1.Text);
then it works..
I hope you can help :)

How do I fix this nullreferenceexception in my listbox? [duplicate]

This question already has answers here:
What is a NullReferenceException, and how do I fix it?
(27 answers)
Closed 8 years ago.
Sorry for asking this question again but, I don't really know how to debug this.
The debugger is giving me nullreferenceexception in this line:
if (listBox1.SelectedItem.ToString() == "Chicken $15")
I figure that the reason why it is giving me nullreferenceexception is because listbox1 is null so I think I have to initialize it. But how? I dont know how to initialize a listbox.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace lab6
{
public partial class Form1 : Form
{
double total = 0;
int x = 0;
string ord = "";
public Form1()
{
InitializeComponent();
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void placeToolStripMenuItem_Click(object sender, EventArgs e)
{
checkBox1.Checked = false;
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
radioButton4.Checked = false;
switch (checkBox1.Checked)
{
case true:
total += 1;
ord += "Water\n";
break;
}
if (comboBox1.Text == "Extra Meat")
{
total += 1;
ord += ord + "Extra Meat\n";
}
if (comboBox1.Text == "Extra Rice")
{
total += 1;
ord += "Extra Rice\n";
}
if (comboBox1.Text == "Extra Veggies")
{
total += 1;
ord += "Extra Veggies\n";
}
if (listBox1.SelectedItem.ToString() == "Chicken $15")
{
total += 15;
ord += " Chicken\n";
}
else { }
if (listBox1.SelectedItem.ToString() == "Pizza $8") //< my pathetic attempt to figure it out with intelisense
{
total += 8;
ord += "Pizza\n";
}
else
{
}
if (listBox1.SelectedItem.ToString() == "Spaghetti $12")//< my pathetic attempt to figure it out with intelisense
{
total += 12;
ord += " Spaghetti\n";
}
else { }
if (listBox1.SelectedItem.ToString() == "Fries $8")
{
total += 8;
ord += " Fries\n";
}
else { }
if (listBox1.SelectedItem.ToString() == "Burger $10")
{
total += 10;
ord += " Burger\n";
}
else { }
//radiobutton
if (radioButton1.Checked)
{
total+=5;
ord += "Pineapple Juice\n";
}
if (radioButton2.Checked)
{
total+=6;
ord += "Mango Juice\n";
}
if (radioButton3.Checked)
{
total+=7;
ord += "Apple Juice\n";
}
if (radioButton4.Checked)
{
total+=8;
ord += "Orange Juice\n";
}
MessageBox.Show("Order Done");
listBox1.SelectedItems.Clear();
}
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
ord = "";
total = 0;
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void displayToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Order: " + ord+"\nTotal: "+total);
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
It looks like you're assuming that listBox1.SelectedItem is never null, try doing somthing like
if (listBox1.SelectedItem != null)
{
// code here
}

Categories

Resources