Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
535
Access templated column TextBox value in Javascript
posted

Hi,

I have a requirement to let user enter amount in grid's templated column TextBox. Page also has another textbox called 'Total Amount' out of Webgrid. So, user enters value in 'Total Amount' and then different amounts in grid row's textbox. Finally when user clicks on 'Submit' button, on clientside, I need the code to check whether grid total is equal to 'Total Amount' TextBox value. If yes, let postback happen. Otherwise, alert user and stop him from doing postback.

This is what I am trying to do. But, not able to get templated column TextBox Value.

I appreciate your response.

<script type="text/javascript">

    <!--
    function callPostBack()
 {
    var grid=igtbl_getGridById("UltraWebGrid1");
    var str = document.getElementById('TextBox1').value;
   
   
    var count  = 0;
    var value;
   
    for(var i=0; i < grid.Rows.length; i++)
    {         
              
        var status = grid.Rows.getRow(i).getCellFromKey("TemplatedColumn").getValue();
        count = count + status; 
          
              
    }
    alert(count);


    if(count != str)
        {
           
        alert("Please amount is not same");
        return false;
        }
        else
            return true;

}
    -->
    </script>
 

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return callPostBack();" />

Thanks,

Katta

Parents
No Data
Reply
  • 28464
    posted

    I think the problem here is that document.getElementById needs the client-side ID of the textbox and not the server-side one. If a server control is nested inside a template(or any INamingContainer for that matter), the client side and server-side APIs wil differ.

    So I have a couple of suggestions:

    1. Try using document.getElementById("<%= TextBox1.ClientID %>") for getting the textbox. However this may not always work if the TextBox1 server control is not in the context of the javascript code block.

    2.  Try something like tha:

    grid.Rows.getRow(i).getCellFromKey("TemplatedColumn").getElement().getElementsByTagName("INPUT")[0]

Children
No Data