I've got a Problem with my code in asp.net using jQuery to alter a link text. Weird thing about it: I have to click exactly four times so it works and my link changes after that. Can anyone tell me what could be the reason for this strange bevahiour? Any caching issues?
This is my code in asp.net:
<asp:GridView ID="gvSurveys" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid" RowStyle-CssClass="aspBoundField" Width="100%">
<Columns>
<asp:TemplateField HeaderStyle-CssClass="aspBoundField_Header" ItemStyle-CssClass="aspBoundField" HeaderText="Lieferant">
<ItemTemplate>
<a href="javascript:void(0)" class="linkfield" id="surveyListSupplierLink_<%# Eval("ID") %>" onclick="document.getElementById('surveyList').style.display='none'"><%# Eval("Lieferant.Name") %></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-CssClass="aspBoundField_Header" ItemStyle-CssClass="aspBoundField" HeaderText="Fragebogenkatalog">
<ItemTemplate>
<a href="javascript:void(0)" class="linkfield" id="surveyListCatalogueLink_<%# Eval("ID") %>" onclick="document.getElementById('surveyList').style.display='none'"><%# Eval("Fragebogenkatalog.Name") %></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-CssClass="aspBoundField_Header" ItemStyle-CssClass="aspBoundField" HeaderText="Status">
<ItemTemplate>
<!-- This is where the changes should happen: -->
<a href="javascript:void(0)" class="linkfield" id="surveyListStatusLink_<%# Eval("ID") %>" onclick="document.getElementById('surveyList').style.display='none'"><%# Eval("Status_Text") %></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And here comes my JavaScript / jQuery:
$("#surveyListStatusLink_" + surveyData.Id).html(surveyData.StatusText);
So basically what I want to happen is that when a certain event is fired (in this case it's a click on my link) the link title should be changed. It all works out fine, I bound the click event like this:
<script type="text/javascript">
$(document).on("click", ".linkfield", function () {
numberStart = $(this).attr("id").indexOf("_") + 1;
SelectedId = $(this).attr("id").substring(numberStart, $(this).attr("id").length);
LoadData(SelectedId);
$("#fade").fadeIn(300, "swing", function () { $("#surveyForm").fadeIn(200); });
})
</script>
the LoadData function that contains the jQuery statement:
function LoadData(id) {
$.ajax({
type: "POST",
url: "SurveyList.aspx/GetData",
data: '{surveyId: "' + id + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnLoadDataSuccess,
failure: function (response) {
alert(response.d);
}
});
}
function OnLoadDataSuccess(response) {
if (response.d.substring(0,5) == "Error")
alert(response.d);
else {
surveyData = jQuery.parseJSON(response.d);
$("#surveyFormTitle").html(surveyData.Supplier.Name); // Note: this shows up properly!
$("#surveyListStatusLink_" + surveyData.Id).html(surveyData.StatusText); // This doesn't...
}
}
When I debug it I can see the html value is altered properly, but here comes the problem: It won't show up in the Browser. It's not showing any changes and I'm not quite sure what I'm doing wrong.
Things that I already tried:
Using the .attrib()-function on the title
Using the .fadeOut()-function on the link
Using the .text()-function on the link-element
...but still: No visible changes.
So can anyone tell what's the problem and how i could possibly solve it?
Thanks in advance!