I understand there are few answers quite similar on this site but I am unable to figure out what I am doing wrong here. Full error message are here:
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'ASP.webform1_aspx' does not contain a definition for 'addNumbers' and no extension method 'addNumbers' accepting a first argument of type 'ASP.webform1_aspx' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 37:
Line 38:
Line 39:
Line 40:
Line 41:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function addNumbers()
{
var firstNumber = parseFloat(document.getElementById("TextBox1").value);
var secondNumber = parseFloat(document.getElementById("TextBox2").value);
document.getElementById("TextBox3").value = firstNumber + secondNumber;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>First Number: </td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Second Number: </td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Result: </td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="Button1" runat="server" Text="Add" OnClick="addNumbers()" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
Code from as aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
This:
<asp:Button ID="Button1" runat="server" Text="Add" OnClick="addNumbers()" />
requires your to have OnClick method in code-behind file. I think that you need normal, not server-side button:
<button onclick="addNumbers()">Add</button>
Related
my question was that when I send the request to the web server, of course, the web server will take the request and give me a page that will be in the HTML format so I want to know when the web server will execute asp server-side controls into HTML format than in the Testing. aspx.cs file will be changed as well? it means these two lines int no1 = Convert.ToInt32(textbox1.Text);
int no2 = Convert.ToInt32(textbox2.Text);
these two lines will be converted into like this int no1=Convert.ToInt32(Response["textbox1"]);
int no1=Convert.ToInt32(Response["textbox2"]); these two lines will be converted like this or not
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Testing.aspx.cs" Inherits="login.Testing" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="background-image:url(C:\Users\Sudarshan\source\repos\login\login\Images\uWjEogFLUTBc8mSvagdiuP.jpg)">
<form id="form1" runat="server">
<div>
<table align="center">
<tr>
<td>
Enter the Number 1:<asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Enter the Number 2:<asp:TextBox ID="textbox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<center>
<br />
<br />
<asp:Button ID="button1" runat ="server" Text="Add" Height="38px" OnClick="Unnamed1_Click" Width="101px" /> </center>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
--------------------------------------------------------------
Testing.aspx.cs
using System;
using System.Collections.Generic;
using System. Linq;
using System. Web;
using System.Web.UI;
using System.Web. UI.WebControls;
namespace login
{
public partial class Testing: System.Web. UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Unnamed1_Click(object sender, EventArgs e)
{
int no1 = Convert.ToInt32(textbox1.Text);
int no2 = Convert.ToInt32(textbox2.Text);
int result;
result = no1 + no2;
Response.Write(result);
}
}
}
how do I use a within an UserControl?
I always get the error, that the CheckBox should be placed within a FormTag (with runat=server), which is still existing on the MasterPage and it is not allowed to have two of them ...
Code of UserControl:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ctrlOrderEmailsDialog.ascx.cs" Inherits="WebClient.Controls.ctrlOrderEmailsDialog" %>
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<div id="OrderEmailDialog" runat="server">
<table id="OrderEmailDialogTable">
<tbody>
<tr>
<th>Nr.</th>
<td>
<asp:Label ID="labelId" runat="server"></asp:Label></td>
</tr>
<tr>
<th>ReturnReceipt:</th>
<td>
<%--<telerik:RadButton ID="checkboxReturnReceipt" runat="server" ToggleType="CustomToggle" ButtonType="ToggleButton" AutoPostBack="false">
<ToggleStates>
<telerik:RadButtonToggleState Text="UnChecked" PrimaryIconCssClass="rbToggleCheckbox"></telerik:RadButtonToggleState>
<telerik:RadButtonToggleState Text="Filled" PrimaryIconCssClass="rbToggleCheckboxFilled"
Selected="true"></telerik:RadButtonToggleState>
<telerik:RadButtonToggleState Text="Checked" PrimaryIconCssClass="rbToggleCheckboxChecked"></telerik:RadButtonToggleState>
</ToggleStates>
</telerik:RadButton>--%>
<asp:CheckBox ID="checkboxReturnReceipt" runat="server" />
</td>
</tr>
<tr>
<th>Mailtext:</th>
<td>
<asp:Label ID="OrderEmailText" runat="server">
</asp:Label>
</td>
</tr>
</tbody>
</table>
</div>
Form Tag (already existing within the SiteMaster page):
<form id="MainForm" runat="server">
System.Web.HttpException:
"The control ctrlOrderEmailsDialog_checkboxReturnReceipt type CheckBox must be positioned in a form tag with runat = server." which is existing ...
Can you guys give me a small hint?
Thank you.
//SiL
I always got this error:Compiler Error Message: CS0103: The name 'txtUserName' does not exist in the current context
mypage.aspx
<% #Page Language="C#" Inherits="myclass" Src="myclass.cs" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Form</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Username:
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="Writedata" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
myclass.cs
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Text;
public class myclass:Page
{
protected void WriteData(object sender, EventArgs e){
string customer_id=txtUserName.Text;
string postData="customer_id="+customer_id;
byte[] data= Encoding.UTF8.GetBytes (postData);
// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://myserverurl.com/mypage.php");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();
}
}
Any help here?
Thanks,
Try changing your class declaration to "public partial class myclass:System.Web.UI.Page". The partial keyword is, I believe, critical for the compiler to know the balance of the class definition is created in temp/intermediate files it won't know about otherwise.
I am new to this programming language and I need help with this. Not very sure what is wrong. But it kept prompting the error below and it would not display the data from MySQL workbench database.
Server Error in '/' Application.
--------------------------------------------------------------------------------
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'Nname.name'.
Source Error:
Line 1: <%# Master Language="C#" AutoEventWireup="true" CodeBehind="name.Master.cs" Inherits="Nname.name" %>
This is my form page:
<asp:Content ID="Content2" ContentPlaceHolderID="phContent" runat="server">
<table>
<tr>
<th>
ID
</th>
<th>
Name
</th>
<th>
Country Code
</th>
<th>
Disctrict
</th>
<th>
Population
</th>
</tr>
<tr class="large">
<td>
<asp:Label ID="ID" runat="server" Text=""></asp:Label>
</td>
<td>
<asp:Label ID="Name" runat="server" Text=""></asp:Label>
</td>
<td>
<asp:Label ID="CountryCode" runat="server" Text=""></asp:Label>
</td>
<td>
<asp:Label ID="District" runat="server" Text=""></asp:Label>
</td>
<td>
<asp:Label ID="Population" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</asp:Content>
This is my database code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace P1
{
public class records
{
MySqlConnection con = null;
MySqlCommand cmd = null;
MySqlDataReader rdr ;
//DataSet ds = new DataSet(cmd,con); //
MySqlDataAdapter da = new MySqlDataAdapter();
public void read()
{
try
{
con = new MySqlConnection("Server=myServerName;Database=myDatabaseName;Uid=myID;Pwd=myPassword");
con.Open();
string cmd = "SELECT * FROM city WHERE ID=6;";
//da.Fill(ds);
con.Close();
}
catch()
{ }
}
}
}
You need to edit your master page and change
Inherits="Nname.name"
to
Inherits="name.name"
or
Inherits="name.master"
The code for the asp.net page is:
<div class="facebox_content">
<% if (CurrentUser.Role == "Free")
{
%>
<table cellpadding="0" cellspacing="0" style="border-collapse:collapse;width:380px;">
<tr>
<td>
User Name :
</td>
<td>
Membership Cost :
</td>
</tr>
<tr>
<td style="width:190px;">
<asp:TextBox ID="txtUserName" Enabled="false" runat="server" Text="<%= CurrentUser.Name %>"/>
</td>
<td style="width:190px;">
<asp:TextBox ID="txtCost" Enabled="false" runat="server" Text="2000"/>
</td>
</tr>
<tr>
<td>
<br />
Cheque / Draft No.:
</td>
<td>
<br />
Bank Drawn On :
</td>
</tr>
<tr>
<td style="width:190px;">
<asp:TextBox ID="txtChqNo" runat="server"></asp:TextBox>
</td>
<td style="width:190px;">
<asp:TextBox ID="txtBankName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<br />
Date :
</td>
<td>
<br />
City :
</td>
</tr>
<tr>
<td style="width:190px;">
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
</td>
<td style="width:190px;">
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<%
}
else if(CurrentUser.Role == "Pending")
{
%>
<p style="text-align:justify;">
Your Request is pending with our Administrators.
Please be patient while your request is processed.
Usually it takes 2-4 Days for your request to be processed after the payment has been received.
</p>
<%
}
else if(CurrentUser.Role == "Paid")
{
%>
<p style="text-align:justify;">
You are already a Paid Member of Website
</p>
<%
}
%>
The code for the C# file is:
protected void Page_PreInit(object sender, EventArgs e)
{
this.Theme = CurrentUser.Theme;
}
protected void Page_Load(object sender, EventArgs e)
{
txtUserName.Text = CurrentUser.Name;
ConfirmButton.Attributes.Add("onclick", "javascript:document.getElementById('" + lblMsg.ClientID + "').style.display='none';");
if (CurrentUser.Role != "Free")
ConfirmButton.Visible = false;
}
The code is giving the following error:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.Add(Control child) +8678903
System.Web.UI.PageTheme.SetStyleSheet() +478
System.Web.UI.Page.OnInit(EventArgs e) +8699660
System.Web.UI.Control.InitRecursive(Control namingContainer) +333
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378
Please some one help me out..!!
Maybe you can try in another way:
Aspx:
<asp:PlaceHolder runat="server" ID="FreeHolder" Visible="false">
<table> ... </table>
</asp:PlaceHolder>
<asp:PlaceHolder runat="server" ID="PendingHolder" Visible="false">
<p style="text-align:justify;">
Your Request is pending with our Administrators. ...
</p>
</asp:PlaceHolder/>
<asp:PlaceHolder runat="server" ID="PaidHolder" Visible="false">
...
</asp:PlaceHolder/>
Code-Behind:
if (CurrentUser.Role == "Free")
{
FreeHolder.Visible = true;
} else if (CurrentUser.Role == "Pending") {
PendingHolder.Visible = true;
} else if (CurrentUser.Role == "Paid") {
PaidHolder.Visible = true;
}