write server side code in aspx.cs page

In our previous asp.net tutorial we learnt about aspx page and aspx.cx page. The aspx page is for design purpose and the aspx.cs page allow programmer to write server side code.

how to write C# code in aspx.cs page

We know that the server side code written in aspx.cs page. The C# server side code execute when some event fired like button click event. Here, we take an example to execute server side code on button click event. When we make click on button then code will be execute which written on button click events. To go to button click events, double click on the button which we added on web form. OR open button properties windows and click top of windows events button next to the properties icon.

Button Control -> Double click -> events

Now, add button control on web form and double click on it to write server side code on button click events.

write c# code in button click event asp.net

write c# code in button click event asp.net

Here is the Default.aspx.cs page for write c# server side code in button click events.

protected void Button1_Click(object sender, EventArgs e) { }

Here, Button1_Click is a method of execute some code written in it. The Button1 is a Id of the button control. When we change the Id of button control and then create click event the click event could be changed with new name. Write server side code in curly brackets for the button code.

write c# code in button click event asp.net

write c# code in button click event asp.net

Leave a Reply

Your email address will not be published. Required fields are marked *

7 + 8 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">