Click here to Skip to main content
15,888,051 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to write code in aspx page which connect to database and display data in page. i dont want to use code-behind page or .cs file
Posted
Comments
SoMad 16-Jun-12 3:04am    
How much work have you done on this? Where are you stuck?

Soren Madsen
Member 10508763 27-Jan-19 5:57am    
I have a css button I need the button click go-to other pages in aspx.net

Hi,
While adding a new page to the project in right corner you will get a check box named "Place code in separate file" just uncheck that.

http://www.c-sharpcorner.com/uploadfile/NikhilJohari/single-file-mode-in-Asp-Net/[^]

--AK
 
Share this answer
 
Comments
Mohamed Mitwalli 17-Jun-12 8:28am    
5+
when we add a new page in solution then there is a checkbox which is "Place code in Seprate file" uncheck it. then you can code in aspx page.
 
Share this answer
 
Hello Manohar
Please Find this

XML
<%@ Page Language="C#" %>
<script runat="server">
void Button1_Click(Object sender, EventArgs e)
{
    Label1.Text = "Clicked at " + DateTime.Now.ToString();
}
</script>
<html>
<head>
  <title>Single-File Page Model</title>
</head>
<body>
  <form runat="server">
    <div>
       <asp:Label id="Label1"
         runat="server" Text="Label">
       </asp:Label>
       <br />
       <asp:Button id="Button1"
         runat="server"
         onclick="Button1_Click"
         Text="Button">
      </asp:Button>
    </div>
  </form>
</body>
</html>
 
Share this answer
 
Comments
Mohamed Mitwalli 17-Jun-12 8:30am    
5+
Solution 4
This is you can do by two ways:
1)By using Render Block- include all your code requred for database in block
HTML
 <%  

%> 

2)by using script tag:include all ur code in button click event into this tag as follows.
ASP.NET
<script  runat="server">
sub Button_click(byval s as object, byval e as EventArgs)
Dim con as sqlconnection
dim cmd as sqlcommand
con=new sqlconnection("place ur conn string here")
cmd=new sqlacommand("select * from table", con)
dim dr as sqldatareader=cmd.executereader()
while dr.read()
   response.write(dr("col name in ur table")
end while
</script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900