How to Check Which Button is Clicked in ASP.NET CORE

How to Check Which Button is Clicked in ASP.NET CORE

ASP.NET MVC

6 лет назад

24,223 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@mehedihasan-kf4uy
@mehedihasan-kf4uy - 13.06.2024 11:19

most helpful video

Ответить
@MK-kl4es
@MK-kl4es - 31.05.2023 19:50

21 <div class="container d-flex justify-content-center">
<table width="220" id="Table1">
<tr style="text-align:center;">
<th><a href="#" style="text-decoration: underline;">value1</a></th>
<th><a href="#" style="text-decoration: underline;">value2</th>
<th><a href="#" style="text-decoration: underline;">value3</th>
</tr>
<tr>
<td>id</td>
<td>name</td>
<td>surname</td>
</tr>
</table>
</div>

<script>
const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;

const comparer = (idx, asc) => (a, b) => ((v1, v2) =>
v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2)
)(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx));

// do the work...
document.querySelectorAll('th').forEach(th => th.addEventListener('click', (() => {
const table = th.closest('table');
Array.from(table.querySelectorAll('tr:nth-child(n+2)'))
.sort(comparer(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc))
.forEach(tr => table.appendChild(tr) );
})));
</script>

Ответить
@MK-kl4es
@MK-kl4es - 31.05.2023 19:47

10protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.Open();
con.ConnectionString = @"";
SqlCommand com = new SqlCommand();
com.Connection = con;
if (DropDownList1.SelectedIndex == 1)
{
com.CommandText = "SELECT english, describe FROM store WHERE french = @word ";
com.Parameters.AddWithValue("@word", TextBox1.Text);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = com;
da.Fill(ds);
TextBox2.Text = ds.Tables[0].Rows[0][0].ToString();
TextBox3.Text = ds.Tables[0].Rows[0][1].ToString();
}
else if (DropDownList1.SelectedIndex == 2)
{
com.CommandText = "SELECT french, describe FROM store WHERE english = @word ";
com.Parameters.AddWithValue("@word", TextBox1.Text);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = com;
da.Fill(ds);
TextBox2.Text = ds.Tables[0].Rows[0][0].ToString();
TextBox3.Text = ds.Tables[0].Rows[0][1].ToString();
}

}

Ответить
@imrerozsumberszki389
@imrerozsumberszki389 - 07.08.2022 19:47

I think it is not a good pratice. Your button became to "submit" type button due to asp-action="check" method.
If you give the buttons a type="button" it won't work because it won't go to the check controller. The first time you typed <form asp-action="check"> this was your feeling, but then you deleted it, but here comes the best method:
<form asp-action="check">
<button type="submit" name="button" value="first">First</button>
<button type="submit" name="button" value="second">Second</button>
</form>

Ответить
@esalagin
@esalagin - 09.02.2022 16:39

Спасибо🙏💕

Ответить
@ericramirez2769
@ericramirez2769 - 22.01.2022 08:31

Thank you sir!

Ответить
@satra1102
@satra1102 - 12.01.2020 03:02

omg why those conditions, Tempdata[buttonval] = button + "button clicked"
is enough

Ответить
@vikasmalik9873
@vikasmalik9873 - 08.01.2020 21:24

Thank you, sir. after two weeks finally, I find the solution because of this video. :D

Ответить
@predragradoman1505
@predragradoman1505 - 19.01.2019 13:31

Nothing happened when I clicked on the button and I did the same thing. I wanna calculate 2 numbers without submit type of button.

Ответить
@MultiLeechCZ
@MultiLeechCZ - 03.01.2019 12:01

Very nice, but how to pass multiple params to controller pls ?

Ответить
@phucnguyeninh7225
@phucnguyeninh7225 - 29.03.2018 00:32

Can you make a video that put user in a group like a social networking page pleAse?

Ответить
@A4amenvi
@A4amenvi - 26.03.2018 19:10

I love your page because you treat relevant topics only. You're brief and on point. Great job bro really thank you.

Ответить