how to create controller in asp.net web form without taking controller class we should take only normal class and how to do routing in that class and make that class work exctly as controller
Loading
how to create controller in asp.net web form without taking controller class we should take only normal class and how to do routing in that class and make that class work exctly as controller
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 22, 2023, 9:47 AM EDT
In ASP.NET Web Forms, there is no specific controller class like in ASP.NET MVC. However, you can create a regular class and use it to handle requests by implementing the
IHttpHandlerinterface.public class MyHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { // Handle the request here string response = "Hello World!"; context.Response.Write(response); } public bool IsReusable { get { return false; } } }Vishal YelveRank #178 · 13.6K reputationPosted Mar 20, 2023, 10:12 AM EDT
Hi Jaya,
Please refer below links, Hope this might help
https://www.c-sharpcorner.com/uploadfile/dacca2/routing-in-asp-net-web-form-application/
https://www.aspsnippets.com/Articles/Implement-URL-Routing-in-ASPNet-Web-Forms-40.aspx
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 22, 2023, 9:49 AM EDT
To use this class to handle requests, you need to register it in the RouteConfig class. You can do this by adding a new route to the RouteTable:
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.Ignore("{resource}.axd/{*pathInfo}"); // Register the custom route routes.Add(new Route("myroute", new MyRouteHandler())); } } public class MyRouteHandler : IRouteHandler { public IHttpHandler GetHttpHandler(RequestContext requestContext) { return new MyHandler(); } }Jaya PrakashRank #1,293 · 1.3K reputationPosted Mar 21, 2023, 12:46 AM EDT
debugger; function CallPrint(strid) { var prtContent = document.getElementById(strid); var winprint = (window.open(",", 'left=0,top=0,width=1,hight=1,toolbar=0,scrollbar=0,starts=0')); winprint.document.write(prtContent.innerHTML); winprint.document.close(); winprint.focus(); winprint.print(); prtContent.innerHTML = stroldone; } --%>Jaya PrakashRank #1,293 · 1.3K reputationPosted Mar 21, 2023, 1:19 AM EDT
private void GetCustomersPageWise(int pageIndex) { using (SqlCommand cmd = new SqlCommand("GetCustomersPageWise", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@PageIndex", pageIndex); cmd.Parameters.AddWithValue("@PageSize", int.Parse(ddlPageSize.SelectedValue)); cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4); cmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output; con.Open(); IDataReader idr = cmd.ExecuteReader(); GridView1.DataSource = idr; GridView1.DataBind(); idr.Close(); con.Close(); int recordCount = Convert.ToInt32(cmd.Parameters["@RecordCount"].Value); this.PopulatePager(recordCount, pageIndex); } }CREATE PROCEDURE GetCustomersPageWise @PageIndex INT = 1 ,@PageSize INT = 10 ,@RecordCount INT OUTPUT AS BEGIN SET NOCOUNT ON; SELECT ROW_NUMBER() OVER ( ORDER BY namek ASC )AS RowNumber ,namek ,passwrd ,gender ,email ,mobileno ,country ,stat ,city ,img1 ,img2 ,amount INTO #Results FROM newtable SELECT @RecordCount = COUNT(*) FROM #Results SELECT * FROM #Results WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1 DROP TABLE #Results ENDvoid BindData() { SqlCommand cmd = new SqlCommand("select * from newtable", con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); if (ViewState["TotalPrice"] == null) { Decimal dPrice = 0; for (int i = 0; i (10); } ViewState["TotalPrice"] = dPrice; } GridView1.DataSource = dt; GridView1.DataBind(); }alter table newtable add amount numeric(18,2)private void PopulatePager(int recordCount, int currentPage) { double dblPageCount = (double)((decimal)recordCount / decimal.Parse(ddlPageSize.SelectedValue)); int pageCount = (int)Math.Ceiling(dblPageCount); List pages = new List(); if (pageCount > 0) { pages.Add(new ListItem("First", "1", currentPage > 1)); for (int i = 1; i <= pageCount; i++) { pages.Add(new ListItem(i.ToString(), i.ToString(), i != currentPage)); } pages.Add(new ListItem("Last", pageCount.ToString(), currentPage < pageCount)); } rptPager.DataSource = pages; rptPager.DataBind(); }Jaya PrakashRank #1,293 · 1.3K reputationPosted Mar 21, 2023, 3:28 AM EDT