How to avoid overpaying for a stock

I placed an online order for 100 shares of a stock at $27 per share, but by the time the brokerage filled it, the stock's price had climbed to $35 per share. Do the rules limit the amount of time a brokerage can take to complete a stock transaction? If not, how can I keep this from happening again?