![]() |
How to develop
I have a general question of how to do this?
I have a webpage with 5 buttons and a 1 text box. The idea is if I click on any of the buttons a text should appear in the text box related to the button. My question is what is the best way to program this? I tried to use AJAX and update panel, but it's too slow, when I click on the button it takes 1 or 2 seconds to display the text, long enough for user to wonder what's going on and click on the button again or click on something else. Should I use hidden field for each button (with JavaScript) and move the text from the hidden field in to the Text box when user clicks on a button? Should I use 5 hidden text boxes and show / hide them when user clicks on a button? Which one is the most efficient? Should I use ASP.NET buttons or HTML buttons or something else? Or is there a better way to do this? Thank You Peter |
Re: How to develop
Hi,,
if you want to no delay... javascript is good since all happens in client side... Best of luck Munna |
RE: How to develop
Hi Peter,
I agree with Munna that using pure client-side script to do the message displaying task is preferred(if the messages can be statically determined after page render ) and postback or AJAX is unnecessary. here is very simple page to demonstrate the javascript approach: # I used a statically defined javascript array, for your scenario, you can also use Page.ClientScript.RegisterXXX method to emit such a client script variable in codebehind(such as from some database records...): =============================== <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script type="text/javascript"> var messages = new Array("message1","message2","message3","message4", "message5"); function display_message(index) { alert(messages[index]); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="txtMessage" runat="server"></asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" Text="Button1" OnClientClick="display_message(0);" /> <asp:Button ID="Button2" runat="server" Text="Button2" OnClientClick="display_message(1);" /> <asp:Button ID="Button3" runat="server" Text="Button3" OnClientClick="display_message(2);" /> <asp:Button ID="Button4" runat="server" Text="Button4" OnClientClick="display_message(3);" /> <asp:Button ID="Button5" runat="server" Text="Button5" OnClientClick="display_message(4);" /> </div> </form> </body> </html> ================================ Hope this helps. Sincerely, Steven Cheng Microsoft MSDN Online Support Lead Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- >From: "Peter" <czupet@nospam.nospam> >Subject: How to develop >Date: Wed, 30 Jul 2008 00:55:16 -0500 > >I have a general question of how to do this? > >I have a webpage with 5 buttons and a 1 text box. The idea is if I click on >any of the buttons a text should appear in the text box related to the >button. >My question is what is the best way to program this? > >I tried to use AJAX and update panel, but it's too slow, when I click on the >button it takes 1 or 2 seconds to display the text, long enough for user to >wonder what's going on and click on the button again or click on something >else. > >Should I use hidden field for each button (with JavaScript) and move the >text from the hidden field in to the Text box when user clicks on a button? >Should I use 5 hidden text boxes and show / hide them when user clicks on a >button? > >Which one is the most efficient? > >Should I use ASP.NET buttons or HTML buttons or something else? > >Or is there a better way to do this? > >Thank You > > >Peter > > > |
Re: How to develop
Thank you!
This is a good idea, just what I was looking for! "Steven Cheng [MSFT]" <stcheng@online.microsoft.com> wrote in message news:Vetr7Ji8IHA.4744@TK2MSFTNGHUB02.phx.gbl... > Hi Peter, > > I agree with Munna that using pure client-side script to do the message > displaying task is preferred(if the messages can be statically determined > after page render ) and postback or AJAX is unnecessary. here is very > simple page to demonstrate the javascript approach: > > # I used a statically defined javascript array, for your scenario, you can > also use Page.ClientScript.RegisterXXX method to emit such a client script > variable in codebehind(such as from some database records...): > =============================== > <html xmlns="http://www.w3.org/1999/xhtml"> > <head runat="server"> > <title>Untitled Page</title> > <script type="text/javascript"> > > var messages = new > Array("message1","message2","message3","message4", "message5"); > > function display_message(index) > { > alert(messages[index]); > } > </script> > </head> > <body> > <form id="form1" runat="server"> > <div> > > <asp:TextBox ID="txtMessage" runat="server"></asp:TextBox> > <br /> > <asp:Button ID="Button1" runat="server" Text="Button1" > OnClientClick="display_message(0);" /> > <asp:Button ID="Button2" runat="server" Text="Button2" > OnClientClick="display_message(1);" /> > <asp:Button ID="Button3" runat="server" Text="Button3" > OnClientClick="display_message(2);" /> > <asp:Button ID="Button4" runat="server" Text="Button4" > OnClientClick="display_message(3);" /> > <asp:Button ID="Button5" runat="server" Text="Button5" > OnClientClick="display_message(4);" /> > > </div> > </form> > </body> > </html> > > ================================ > > Hope this helps. > > Sincerely, > > Steven Cheng > > Microsoft MSDN Online Support Lead > > > Delighting our customers is our #1 priority. We welcome your comments and > suggestions about how we can improve the support we provide to you. Please > feel free to let my manager know what you think of the level of service > provided. You can send feedback directly to my manager at: > msdnmg@microsoft.com. > ================================================== > This posting is provided "AS IS" with no warranties, and confers no > rights. > -------------------- >>From: "Peter" <czupet@nospam.nospam> >>Subject: How to develop >>Date: Wed, 30 Jul 2008 00:55:16 -0500 > >> >>I have a general question of how to do this? >> >>I have a webpage with 5 buttons and a 1 text box. The idea is if I click > on >>any of the buttons a text should appear in the text box related to the >>button. >>My question is what is the best way to program this? >> >>I tried to use AJAX and update panel, but it's too slow, when I click on > the >>button it takes 1 or 2 seconds to display the text, long enough for user > to >>wonder what's going on and click on the button again or click on something >>else. >> >>Should I use hidden field for each button (with JavaScript) and move the >>text from the hidden field in to the Text box when user clicks on a >>button? >>Should I use 5 hidden text boxes and show / hide them when user clicks on > a >>button? >> >>Which one is the most efficient? >> >>Should I use ASP.NET buttons or HTML buttons or something else? >> >>Or is there a better way to do this? >> >>Thank You >> >> >>Peter >> >> >> > |
Re: How to develop
You're welcome Peter.
Have a good day! Sincerely, Steven Cheng Microsoft MSDN Online Support Lead Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com. ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif ications. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- >From: "Peter" <czupet@nospam.nospam> >References: <uNUfYjg8IHA.3768@TK2MSFTNGP04.phx.gbl> <Vetr7Ji8IHA.4744@TK2MSFTNGHUB02.phx.gbl> >Subject: Re: How to develop >Date: Wed, 30 Jul 2008 07:57:51 -0500 > >Thank you! > >This is a good idea, just what I was looking for! > >"Steven Cheng [MSFT]" <stcheng@online.microsoft.com> wrote in message >news:Vetr7Ji8IHA.4744@TK2MSFTNGHUB02.phx.gbl... >> Hi Peter, >> >> I agree with Munna that using pure client-side script to do the message >> displaying task is preferred(if the messages can be statically determined >> after page render ) and postback or AJAX is unnecessary. here is very >> simple page to demonstrate the javascript approach: >> >> # I used a statically defined javascript array, for your scenario, you can >> also use Page.ClientScript.RegisterXXX method to emit such a client script >> variable in codebehind(such as from some database records...): >> =============================== >> <html xmlns="http://www.w3.org/1999/xhtml"> >> <head runat="server"> >> <title>Untitled Page</title> >> <script type="text/javascript"> >> >> var messages = new >> Array("message1","message2","message3","message4", "message5"); >> >> function display_message(index) >> { >> alert(messages[index]); >> } >> </script> >> </head> >> <body> >> <form id="form1" runat="server"> >> <div> >> >> <asp:TextBox ID="txtMessage" runat="server"></asp:TextBox> >> <br /> >> <asp:Button ID="Button1" runat="server" Text="Button1" >> OnClientClick="display_message(0);" /> >> <asp:Button ID="Button2" runat="server" Text="Button2" >> OnClientClick="display_message(1);" /> >> <asp:Button ID="Button3" runat="server" Text="Button3" >> OnClientClick="display_message(2);" /> >> <asp:Button ID="Button4" runat="server" Text="Button4" >> OnClientClick="display_message(3);" /> >> <asp:Button ID="Button5" runat="server" Text="Button5" >> OnClientClick="display_message(4);" /> >> >> </div> >> </form> >> </body> >> </html> >> >> ================================ >> >> Hope this helps. >> >> Sincerely, >> >> Steven Cheng >> >> Microsoft MSDN Online Support Lead >> |
Re: How to develop
You're welcome Peter.
Have a good day! Sincerely, Steven Cheng Microsoft MSDN Online Support Lead Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@microsoft.com. ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif ications. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- >From: "Peter" <czupet@nospam.nospam> >References: <uNUfYjg8IHA.3768@TK2MSFTNGP04.phx.gbl> <Vetr7Ji8IHA.4744@TK2MSFTNGHUB02.phx.gbl> >Subject: Re: How to develop >Date: Wed, 30 Jul 2008 07:57:51 -0500 > >Thank you! > >This is a good idea, just what I was looking for! > >"Steven Cheng [MSFT]" <stcheng@online.microsoft.com> wrote in message >news:Vetr7Ji8IHA.4744@TK2MSFTNGHUB02.phx.gbl... >> Hi Peter, >> >> I agree with Munna that using pure client-side script to do the message >> displaying task is preferred(if the messages can be statically determined >> after page render ) and postback or AJAX is unnecessary. here is very >> simple page to demonstrate the javascript approach: >> >> # I used a statically defined javascript array, for your scenario, you can >> also use Page.ClientScript.RegisterXXX method to emit such a client script >> variable in codebehind(such as from some database records...): >> =============================== >> <html xmlns="http://www.w3.org/1999/xhtml"> >> <head runat="server"> >> <title>Untitled Page</title> >> <script type="text/javascript"> >> >> var messages = new >> Array("message1","message2","message3","message4", "message5"); >> >> function display_message(index) >> { >> alert(messages[index]); >> } >> </script> >> </head> >> <body> >> <form id="form1" runat="server"> >> <div> >> >> <asp:TextBox ID="txtMessage" runat="server"></asp:TextBox> >> <br /> >> <asp:Button ID="Button1" runat="server" Text="Button1" >> OnClientClick="display_message(0);" /> >> <asp:Button ID="Button2" runat="server" Text="Button2" >> OnClientClick="display_message(1);" /> >> <asp:Button ID="Button3" runat="server" Text="Button3" >> OnClientClick="display_message(2);" /> >> <asp:Button ID="Button4" runat="server" Text="Button4" >> OnClientClick="display_message(3);" /> >> <asp:Button ID="Button5" runat="server" Text="Button5" >> OnClientClick="display_message(4);" /> >> >> </div> >> </form> >> </body> >> </html> >> >> ================================ >> >> Hope this helps. >> >> Sincerely, >> >> Steven Cheng >> >> Microsoft MSDN Online Support Lead >> |
| All times are GMT. The time now is 11:05 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.