How to call Javascript function from server side asp.net
<p>I have a <code>Textbox</code> in <code>GridView</code> I want to change the Label.Text if the text in Textbox is changed. But I am not able call javascript function written in .cs page. Is there any mistake in <code>TbUnitCost_TextChanged</code> method.</p><p>This is my aspx page</p><pre><br /><code><ItemTemplate><br /> <asp:TextBox Style="text-align: right" ID="TbUnitCost" runat="server" Width="80px" Text='<%#Bind("Unit_Cost")%>' AutoPostBack="true" OnTextChanged="TbUnitCost_TextChanged" TextMode="Number"></asp:TextBox><br /> </ItemTemplate><br /></code><br /></pre><p>Code behind Page is as follows</p><pre><br /><code> protected void TbUnitCost_TextChanged (object sender, EventArgs e)<br /> {<br /> GridViewRow currentRow = (GridViewRow)((TextBox)sender).Parent.Parent;<br /> int rowNo = currentRow.RowIndex;<br /> string gridName = "GridWorkExpenses";<br /> TextBox tbunitCost = (TextBox)currentRow.FindControl("TbUnitCost");<br /> int row = Convert.ToInt32(tbunitCost.Text);<br /><br /> tbunitCost.Attributes.Add("onchange","javascript:calculateTotalCost('"+rowNo+"','"+gridName+"');");<br /><br /> }<br /></code><br /></pre><p>and javascript Function is:</p><pre><br /><code><script type ="text/javascript"><br /> function calculateTotalCost(rowNo, GridName) { <br /><br /> if (GridName== 'GridWorkExpenses') {<br /> var rowscount = document.getElementById('<%=GridWorkExpensesSheet.ClientID%>').rows.length;<br /> return calculateTotalUnitCost("GridWorkExpensesSheet", rowscount,rowNo);<br /> }<br /> }<br /> </script> <br /></code><br /></pre><br /><h2>Click here view more answers <a href="http://ift.tt/21bxQUO">http://ift.tt/21bxQUO</a></h2>
Nhận xét
Đăng nhận xét