We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Weird .NET gridview behaviour

dave82_2
dave82_2 Posts: 1,328 Forumite
Hi,

If I create a databound grid view with a footer containing a textbox and a button. The button has the attribute
CommandName="Add" set When I press enter in the textbox a postback occurs however the GridViews RowCommand event does not fire. If I add a second text box the RowCommand event does fire!

Anyone able to help?

Cheers Dave

Comments

  • dave82_2
    dave82_2 Posts: 1,328 Forumite
    So basically if I do this

    <FooterTemplate> 
         <asp:TextBox ID="tbxQuantity" runat="server"></asp:TextBox>
    </FooterTemplate>
    

    it doesn't fire the GridView RowCommand even when I press enter in the textbox

    If I do this it does fire the GridView RowCommand event!!

    [/SIZE]
    <FooterTemplate> 
         <asp:TextBox ID="tbxQuantity" runat="server"></asp:TextBox>
         <asp:TextBox ID="stupidfix" runat="server" style="display:none"></asp:TextBox>
    </FooterTemplate>
    
  • RobTang
    RobTang Posts: 1,064 Forumite
    Its a 'Feature' in asp.net webforms.

    Beacuse asp.net webforms demands only 1 runat server form, it creates problems when you hit enter (ie does a form submit),and it normall tries work out what text box you pressed enter in.

    When you only have a single textbox on the page, it automaticaly assumes that textbox was source and seems to bypass the control checking and doesn't do the correct postback.
  • dave82_2
    dave82_2 Posts: 1,328 Forumite
    Cheers. Got to love these microsoft 'features' :j
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 351.7K Banking & Borrowing
  • 253.4K Reduce Debt & Boost Income
  • 454K Spending & Discounts
  • 244.7K Work, Benefits & Business
  • 600.1K Mortgages, Homes & Bills
  • 177.3K Life & Family
  • 258.4K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.2K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.