Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi everyone,

I am implementing a grid view containing few text boxes. And all those text boxes should not get any type of char value. I have implemented it(on keypress event of jquery by taking the class of the text boxes within grid view) and its working fine. Put that grid within an update panel. But when ever I am generating the gridview on a button click. it is not working. I didn't get any type of error message in browser's console. If I remove the update panel and generate the grid its working. Its not working whenever the gridiew is within Upadte panel and its generating from back end. Any one can help me to get rid of this silly error.

Jquery:
JavaScript
$(document).ready(function () {
            $('.scenario-input').keypress(function (e) {
                alert('aa');
                var a = [];
                var k = e.which;

                for (i = 48; i < 58; i++)
                    a.push(i);

                // allow a max of 1 decimal point to be entered
                if (this.value.indexOf(".") === -1) {
                    a.push(46);
                }

                if (!(a.indexOf(k) >= 0)) e.preventDefault();

                alert('KeyCode: ' + k);
            });
        });


and gridview

XML
<asp:UpdatePanel ID="uy1" runat="server">
                <ContentTemplate>
                    <asp:Button ID="b" runat="server" OnClick="b_Click" />
                    <asp:GridView ID="GridView1" runat="server" Visible="false">
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:TextBox ID="id1" runat="server" class="scenario-input"></asp:TextBox>

                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
            </asp:UpdatePanel>
Posted
Comments
Sergey Alexandrovich Kryukov 8-Apr-15 16:45pm    
What keys did you try to press? Are you sure your text box had keyboard focus?
—SA
Arkadeep De 8-Apr-15 23:51pm    
It will take only decimal values.. That is not a problem. I think the main problem is jquery is not loading after hitting a asp button(on which gridview is generating). and both the gridview and button are placed within an update panel. When I am testing it without update panel its working fine..
Sergey Alexandrovich Kryukov 9-Apr-15 1:02am    
Well, jQuery is not loading after hitting, it is already fully loaded before it happens. :-)
You are not describing any problem, you are talking about your understanding of the reasons of some problem. But what is that problem then?
—SA
Arkadeep De 9-Apr-15 13:59pm    
The problem was it was working in some case and not working in some case. I was trying to help you to solve the problem by sharing my experimented views. Any way I solved it myself. Check the solution, provided by me. Any way thanks.. :)

1 solution

All you need to do is
follow this link...
[^]

follow this link...
 
Share this answer
 
Comments
Arkadeep De 10-Apr-15 14:56pm    
Who is down voting the answer? If you can't answer the question you have no right to down vote that one..And if you are down voting then add a valid answer also...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900