Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my ASP.NET Button control not calling the appointed function?
    primarykey
    data
    text
    <p>I want to set up a search functionality on my web site. The user types some information into a text box and click a search button. Upon clicking the search button, a database is searched using the text in the text box, and the results are displayed in a table. If the text in the text box matches one result from the database perfectly, rather than displaying a list of results the page is populated with detailed information about the matching result.</p> <p>In order to make it easier to match a result exactly, I want to add a button next to each result which "selects" that result, filling the text box with that result's text and therefore populating the page with the details. Here's what I have.</p> <p>Upon clicking the search button, after the check to see if a result is matched exactly, I create a table which contains the results and the buttons:</p> <pre><code>for(int x=0; x &lt; res_list.Length; x++) { TableRow newRow = new TableRow(); TableCell textCell = new TableCell(); TableCell buttonCell = new TableCell(); buttonCell.ID = "bc" + x; Button cellButton = new Button(); cellButton.ID = "btn" + x; textCell.Text = res_list[x]; textCell.Attributes.Add("Width","60%"); cellButton.Text = x.ToString(); // cellButton.OnClientClick = "NameClick"; This property refers to client-side scripts, which I am not using. cellButton.Click += new EventHandler(NameClick); buttonCell.Controls.Add(cellButton); newRow.Cells.Add(firstCell); newRow.Cells.Add(buttonCell); myTable.Rows.Add(newRow); } </code></pre> <p>I have tried both the OnClientClick method and the Click method seen above, both of which have yielded the same results.</p> <p>My NameClick function is as follows:</p> <pre><code>void NameClick(object sender, EventArgs e) { Button sendButton = (Button)sender; int index = Int32.Parse(sendButton.Text); SearchTextBox.Text = myTable.Rows[index].Cells[0].Text; return; } </code></pre> <p>I set up a breakpoint at the beginning of the NameClick function, and when I click one of these buttons it is never reached. Why is this function not being called by my buttons?</p> <p>EDIT: I want to accomplish this without using JavaScript, if possible.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload