How to add button and associated on click in ASP.net
I am working on a ASP.NET site, in which i display results returned by internal search engine to the end user.开发者_如何学Python I am parsing the result creating HTML string to display those results as following
foreach (XmlNode result in results)
{
srHtml = "<li class=\"\" style=\"\">";
srHtml += "<a href=\"" + result.SelectSingleNode("./web:Url", nsmgr).InnerText + "\"> <span class=\"title\">" + result.SelectSingleNode("./web:Title", nsmgr).InnerText + "</span></a> <button>Short This URL</button>\n";
if (result.SelectSingleNode("./web:Description", nsmgr) != null)
srHtml += "<br />" + result.SelectSingleNode("./web:Description", nsmgr).InnerText + "<br />";
srHtml += "<span class=\"url\">" + result.SelectSingleNode("./web:Url", nsmgr).InnerText + "</span></li>\n";
phResults.Controls.Add(new System.Web.UI.LiteralControl(srHtml));
}
I can see that button on result page. But I dont know where can I put the code that run when user clicks on this button. When User clicks on that button, I want to change that button textfield with shorten url.
Can anyone help me out here ?
Regards, Sumit Lonkar
What about doing it this way?:
Button button = new Button();
button.ID = "Button1";
button.Click += new EvandHandler(Button1_Click);
phResults.Controls.Add(button);
And your event handdler:
protected void Button1_Click(object sender, EventArgs e)
{
//Event handler code here
}
精彩评论