Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7665151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:29:19+00:00 2026-05-31T14:29:19+00:00

I want to set up a search functionality on my web site. The user

  • 0

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.

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.

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:

for(int x=0; x < 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);
}

I have tried both the OnClientClick method and the Click method seen above, both of which have yielded the same results.

My NameClick function is as follows:

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;
}

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?

EDIT: I want to accomplish this without using JavaScript, if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:29:21+00:00Added an answer on May 31, 2026 at 2:29 pm

    You use cellButton.OnClientClick = "NameClick";, but do you actually have a NameClick function in your javascript? If not, clicking the button will cause a JS error which will probably block the postback.

    Other than that, it is advisable to assign explicit ID’s to controls which you create programatically. Otherwise the autogenerated ID’s may change on postback, which will prevent control events from firing.

    Something like the following should work (not tested):

    myTable.ID = "someid";
    for (int x=0; x < res_list.Length; x++)
    {
      TableRow newRow = new TableRow();
      newRow.ID = "r" + x;
      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"; // not needed unless you have actual JS for it
      cellButton.Click += new EventHandler(NameClick);
    
      buttonCell.Controls.Add(cellButton);
      newRow.Cells.Add(firstCell);
      newRow.Cells.Add(buttonCell);
      myTable.Rows.Add(newRow);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site collection and I want to set the search center value
Say I want to output a huge set of search results, as XML, into
As in many web applications, when my users log into my site, I set
i want to set first text on my UISearchBar -the text is Search-, and
I want to set some attributes just before the object is serialized, but as
We have some search functionality that can return tens of thousands of results from
I want to set up a search in Lucene (actually Lucene.NET, but I can
I am providing search functionality in my website, when user searches a record then
I Want Set Access level user For Buttons in the forms. example in the
I am building a code which displays user information on search. User information, is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.