How to develop

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

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
 
Hi,,

if you want to no delay... javascript is good since all happens in
client side...

Best of luck

Munna
 
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:
(e-mail address removed).
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
Thank you!

This is a good idea, just what I was looking for!

Steven Cheng said:
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:
(e-mail address removed).
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
From: "Peter" <[email protected]>
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
 
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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
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 said:
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
 
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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
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 said:
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
 
Back
Top