Reputation: 779
I want to perform some actions on label click in client-side. So i have a view:
<telerik:RadMultiPage runat="server" ID="rmpRightBar">
<telerik:RadPageView runat="server" ID="rpvHelpDetails">
//some code
</telerik:RadPageView>
<telerik:RadPageView runat="server" ID="rpvSearchDetails">
<asp:Table runat="server" ID="tblSearchResult">
</asp:Table>
</telerik:RadPageView>
</telerik:RadMultiPage>
And code-behind where I add label in runtime to my view table:
private void SearchResultShow(IEnumerable<HelpModel> helpCollection)
{
var helpResultRow = new TableRow();
foreach (var help in helpCollection)
{
var helpCell = new TableCell();
var label = new Label();
label.ID = "SearchResult_" + help.ID;
label.Text = help.Title;
helpCell.Controls.Add(label);
helpResultRow.Cells.Add(helpCell);
}
tblSearchResult.Rows.Add(helpResultRow);
}
Then I want to access my labels on client side and perform some actions on click.
JavaSctipt code:
$(document).ready(function () {
$('[id*=SearchResult_]').click(function () {
alert("Handler for .click() called.");
});
});
Since i have 2 pageviews i switch between them. And after i switch view my javascript doesn't work.
How can I access asp controls added in runtime by part of it's id using jquery?
Upvotes: 0
Views: 684
Reputation: 6710
Take a RadScriptBlock
in your page and put your javascript
code inside it. Then Add its RadScriptBlock
's Id in your ajax settings
which you are using for switching between views
.
Upvotes: 1
Reputation: 3286
I know this is not what classes are for, but why not use them?
Instead of referencing your elements by ID, you can refer them by class. One caveat is to ensure you are not using classes for any style rule (which you can easily avoid by picking arbitrary names)
Upvotes: 1