Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have an input button of type submit and i want to make a particular set of code to run on clicking the input button.Below is my input button

<input type="submit" value="Submit me"  runat="server"  önclick="submited">


can anyone tell me how to write code behind for this type of input button.Thank you in advance.god bless you
Posted
Updated 19-Dec-22 23:32pm
Comments
Kornfeld Eliyahu Peter 31-Mar-14 6:32am    
This is a pure html tag, it has no code-behind. However your markup hints that there is a JavaScript function named 'submited' somewhere in the page...

Add this in the input tag:
OnServerClick="submited"

then in the code behind, add:
C#
protected void submited(Object sender, EventArgs e)
{
    TextBox1.Text = "hello world";
}

run it, it should post back and fill up the textbox1 with 'hello world'
 
Share this answer
 
v2
Comments
faizel s 2-Apr-14 6:49am    
Thanks for helping me.god bless you
In ASP.NET if you want to associate code behind with a submit button you should use ASP:BUTTON control like in the next example:

<asp:Button ID="saveButton" Text='Save' runat="server" OnClick="saveButton_Click"/>

Then in your code you should implement the method linked with the button above:

C#
protected void saveButton_Click(object sender, EventArgs e)
{
 //....
}


Note that this event handler for your button click will be executed after the Page_Load event.
 
Share this answer
 
v2
Comments
faizel s 2-Apr-14 6:49am    
Thanks for helping me.god bless you
Raul Iloc 2-Apr-14 6:53am    
I am glad that I could help you! If my solution was OK for your you could accept it!
just replace this
<input type="submit" value="Submit me"  runat="server"  önclick="submited">

with
<input type="submit" value="Submit me"  runat="server"  önserverclick="submited">
 
Share this answer
 
Comments
Richard Deeming 20-Dec-22 5:37am    
As already clearly explained in solution 1, almost nine years ago.

Stick to answering new questions unless you have something new to add to the discussion.
Jafar Shah 20-Dec-22 5:41am    
ok. I just came across this thread and wrote my answer for new searchers.
I have noted your advice. Thank you!

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