I have a Page named 'Maths' inheriting from ASP.NET Page. And have a wrapper class containing all the codes for the page. Now when I am clicking a button first control goes to the page load of the 'Maths', then only it goes to the wrapper class. I want only to go to the wrapper class. Can you please help me that. I have already set code behind of the page as wrapper class.
<%@ Page Language="C#" AutoEventWireup="true" Inherits="Wrapper.Maths" CodeBehind="~/WrapSample.cs" %>
<%@ Register TagName="MathsController" TagPrefix="MathsControllerUC" Src="~/MathsController.ascx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body onload="">
<form id="form1" runat="server" >
<div>
<MathsControllerUC:MathsController id="text" runat="server">
</MathsControllerUC:MathsController>
</div>
</form>
</body>
</html>
Maths controller is
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="~/WrapSample.cs" Inherits="Wrapper.MathsController" %>
<div>
<asp:TextBox ID="txtFirst" runat="server">0</asp:TextBox>
</div>
<div>
<asp:TextBox ID="txtSecond" runat="server">0</asp:TextBox>
</div>
<div>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" Width="42px" />
<asp:Button ID="btnSubtract" runat="server" Text="Sub" OnClick="btnSubtract_Click" Width="42px" />
<asp:Button ID="btnMultiple" runat="server" Text="Mul" OnClick="btnMult_Click" Width ="42px" />
<asp:Button ID="btnDivide" runat="server" Text="Div" OnClick="btnDivide_Click" Width="42px" />
</div>
this is my page and my class is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Wrapper
{
public partial class MathsController : System.Web.UI.UserControl
{
protected override void Page_Load( EventArgs e)
{
}
protected override void OnInit()
{
}
public class WrapSample
{
public WrapSample()
{
}
public int Add(int First, int Second)
{
WrapSample.inside obj = new WrapSample.inside();
int sum = obj.add(First, Second);
return sum;
}
public int Sub(int First, int Second)
{
WrapSample.inside obj = new WrapSample.inside();
int sum = obj.Sub(First, Second);
return sum;
}
public int Mul(int First, int Second)
{
WrapSample.inside obj = new WrapSample.inside();
int sum = obj.Mul(First, Second);
return sum;
}
public void Div(int First, int Second, out int res, out int rem)
{
WrapSample.inside obj = new WrapSample.inside();
obj.Div(First, Second, out res, out rem);
}
private class inside
{
public int add(int x, int y)
{
return x + y;
}
public int Sub(int x, int y)
{
return x - y;
}
public int Mul(int x, int y)
{
return x * y;
}
public void Div(int x, int y,out int Res,out int rem)
{
Res = x / y;
rem = x % y;
}
}
}
protected void btnSubtract_Click(object sender, EventArgs e)
{
try
{
WrapSample obj = new WrapSample();
Response.Write(obj.Sub(int.Parse(txtFirst.Text), int.Parse(txtSecond.Text)).ToString());
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void btnMult_Click(object sender, EventArgs e)
{
try
{
WrapSample obj = new WrapSample();
Response.Write(obj.Mul(int.Parse(txtFirst.Text), int.Parse(txtSecond.Text)).ToString());
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void btnDivide_Click(object sender, EventArgs e)
{
try
{
int res, rem;
WrapSample obj = new WrapSample();
obj.Div(int.Parse(txtFirst.Text), int.Parse(txtSecond.Text),out res,out rem);
Response.Write("Quotient is "+res);
Response.Write("\nReminder is " + rem);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
try
{
WrapSample obj = new WrapSample();
int a=int.Parse(txtFirst.Text);
int b=int.Parse(txtSecond.Text);
Response.Write((obj.Add(a,b)).ToString());
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
}
when button click it first goes to the page load function that is in the another page.
I want only go to the class itself. How can I override page load in the code behind class