Why not my javascript passing parameter to code behind method
Hi,i am using repeater to display farmer status. In the repeater in using anchor tag.
when i click it not passing hidden value of our code behind method 'SetFarmerChart()'
but i am getting value of anchor tag 'status_id'.. When page load it is calling perfect
but when i try on anchor click it is not calling..
So how do it..
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
//Do not call this method on pageload
//google.setOnLoadCallback(drawChart);
function drawChart() {
var farmerChartList = document.getElementById('<%=lbFarmerList.ClientID%>');
farmerChartList.style.display = "block";
var activityChartList = document.getElementById('<%=lbActivityList.ClientID%>');
activityChartList.style.display = "none";
var data = new google.visualization.DataTable();
data.addColumn('string', 'Status');
data.addColumn('number', 'TotalStatus');
data.addRows(2);
<%=SetFarmerChart()%>;
var chart = new google.visualization.PieChart(document.getElementById('chart'));
chart.draw(data, { title: 'Farmer Status Details', titleTextStyle: { color: 'Maroon', fontSize: '20', fontStyle: 'normal' }, is3D: 'true', tooltip: { text: 'value' }, pieSliceText: 'value', legend: 'right', width: 540, height: 320 });
}
</script>
<script type="text/javascript">
function showFarmerStatusChart(myStatus) {
document.getElementById('<%=hfStatusID.ClientID%>').value = myStatus
alert(myStatus);
drawChart();
var detailHead = document.getElementById('<%=dDetailHead.ClientID%>');
detailHead.style.display = 'none';
}
</script>
aspx
=====
<div class="container" style="width: 265px; float: left; margin-left: -10px; margin-top: 05px;">
<ul class="list-group">
<li class="list-group-item active" style="background: #eeeeee; color: Black;"><span
class="badge">
<asp:Label ID="lbTotalStatus" runat="server"></asp:Label></span>Status</li>
</ul>
<asp:UpdatePanel ID="upstatusp" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="rpStatus" />
</Triggers>
<ContentTemplate>
<asp:HiddenField ID="hfStatusID" runat="server" ClientIDMode="Static" />
<asp:Repeater ID="rpStatus" runat="server">
<HeaderTemplate>
<ul class="list-group" style="margin-top: -20px;">
</HeaderTemplate>
<ItemTemplate>
<li class="list-group-item" style="font-size: 13px;"><a href="#" onclick="javascript:showFarmerStatusChart(<%#Eval("STATUS_ID")%>)">
<%#Eval("STATUS")%>
</a><span class="badge">
<%# Eval("TOTAL_STATUS")%></span> </li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Cs code
=======
public string SetFarmerChart()
{
DataTable sourceFarmer = null;
StringBuilder returnFarmerValue;
int incVal;
FarmerLogic farmerLogic;
FarmerEntity farmerEntity;
int intStatusID = 0;
try
{
returnFarmerValue = new StringBuilder();
farmerEntity = new FarmerEntity();
if (this.hfStatusID.Value == string.Empty)
{
intStatusID = 0;
}
else
{
intStatusID = Convert.ToInt32(this.hfStatusID.Value);
}
farmerEntity.Mode = "STATUS";
farmerEntity.ModifiedBy = GM.UserID;
farmerEntity.StatusID = intStatusID;
farmerLogic = new FarmerLogic();
sourceFarmer = farmerLogic.SelectFarmerMasterStatusChart(farmerEntity);
if (sourceFarmer == null) { sourceFarmer = null; return string.Empty; }
if (sourceFarmer.Rows.Count <= 0) { sourceFarmer = null; return string.Empty; }
if (sourceFarmer.Rows.Count > 0 && Convert.ToInt32(sourceFarmer.Rows[0]["Total_Status"].ToString()) != 0)
{
returnFarmerValue.Append("data.addColumn('string', 'Status');");
returnFarmerValue.Append("data.addColumn('number', 'Total_Status');");
returnFarmerValue.Append("data.addRows(" + sourceFarmer.Rows.Count + ");");
for (incVal = 0; incVal < sourceFarmer.Rows.Count; incVal++)
{
returnFarmerValue.Append("data.setValue(" + incVal + ", 0, '" + sourceFarmer.Rows[incVal]["Status"] + "');");
returnFarmerValue.Append("data.setValue(" + incVal + ", 1, " + sourceFarmer.Rows[incVal]["Total_Status"] + ");");
}
return returnFarmerValue.ToString();
}
else
{
return returnFarmerValue.ToString();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
sourceFarmer = null;
farmerLogic = null;
}
}