473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Modifying ASP button with javascript variable

I have a situation whereby I need to modify the text string appearing on an
ASP button with some text derived from a Javascript function. But I am
unsure of the correct syntax to do so.

Currently the I am just modifying the text in a SPAN next to the button as
opposed to change the button text itself. But it's not ideal really.

Currently I am have this:

<div id="section2">
<asp:TextBox CssClass="textbox" ID="txtSearch" runat="server"
Width="370px" TabIndex="0" />
<asp:Button ID="cmdDoIt" runat="server" onclick="cmdDoIt" Text="Search"
/>
<script type="text/javascript" language="javascript">
function ChangeOptionName(sText) {
document.getElementById("notify_using_se").innerHT ML = "with " +
sText; }
</script>
<span id="notify_using_se"></span>
</div>

The javascript function is called by the on_click event of an option button
but I want to change Text="Seach" of the ASP button to the text returned by
the Function ChangeOptionName(sText)

Thanks in advance for any guide lines :)

Sep 6 '08 #1
4 1997
There are numerous options.

The first is creating a composite control that outputs the JavaScript to
change the funcationality. Think of this as deriving your own "change
button" from the asp.net button. This is a bit of work, if you are only
using this in one place.

Another is to emit your own script using the button's rendered name. I do
not have an example of this, but it happens server side before you render
the page. Once you have the client side name, you can alter any of the
properties.

You might try just looking at the rendered page and writing JavaScript. I
see this all the time, but I would not do this. Why? If forces you to change
your code every time you alter how the button is rendered. For example, you
find the button would be better in a user control. It is also a potential
maintenance problem. And not wise, esp. since you can get the client side
name from the control server side.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"Sean" <se**@home.comwrote in message
news:5A**********************************@microsof t.com...
>I have a situation whereby I need to modify the text string appearing on an
ASP button with some text derived from a Javascript function. But I am
unsure of the correct syntax to do so.

Currently the I am just modifying the text in a SPAN next to the button as
opposed to change the button text itself. But it's not ideal really.

Currently I am have this:

<div id="section2">
<asp:TextBox CssClass="textbox" ID="txtSearch" runat="server"
Width="370px" TabIndex="0" />
<asp:Button ID="cmdDoIt" runat="server" onclick="cmdDoIt"
Text="Search" />
<script type="text/javascript" language="javascript">
function ChangeOptionName(sText) {
document.getElementById("notify_using_se").innerHT ML = "with " +
sText; }
</script>
<span id="notify_using_se"></span>
</div>

The javascript function is called by the on_click event of an option
button but I want to change Text="Seach" of the ASP button to the text
returned by the Function ChangeOptionName(sText)

Thanks in advance for any guide lines :)
Sep 6 '08 #2
"Sean" <se**@home.comwrote in message
news:5A**********************************@microsof t.com...
<script type="text/javascript" language="javascript">
You should remove the language tag, as that has been deprecated for quite a
while...

document.getElementById("notify_using_se").innerHT ML = "with " + sText;
document.getElementById("<%=cmdDoIt.ClientID%>").v alue = "with " + sText;
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 6 '08 #3

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ur**************@TK2MSFTNGP04.phx.gbl...
"Sean" <se**@home.comwrote in message
news:5A**********************************@microsof t.com...
><script type="text/javascript" language="javascript">

You should remove the language tag, as that has been deprecated for quite
a while...

>document.getElementById("notify_using_se").innerH TML = "with " + sText;

document.getElementById("<%=cmdDoIt.ClientID%>").v alue = "with " + sText;
Perfect thanks for the help!

Sep 6 '08 #4
pretty trivial to change the text of a button:

document.getElementById('<%=cmdDoIt.ClientID%>').v alue = "new caption";

-- bruce (sqlwork.com)
Sean wrote:
I have a situation whereby I need to modify the text string appearing on
an ASP button with some text derived from a Javascript function. But I
am unsure of the correct syntax to do so.

Currently the I am just modifying the text in a SPAN next to the button
as opposed to change the button text itself. But it's not ideal really.

Currently I am have this:

<div id="section2">
<asp:TextBox CssClass="textbox" ID="txtSearch" runat="server"
Width="370px" TabIndex="0" />
<asp:Button ID="cmdDoIt" runat="server" onclick="cmdDoIt"
Text="Search" />
<script type="text/javascript" language="javascript">
function ChangeOptionName(sText) {
document.getElementById("notify_using_se").innerHT ML = "with " +
sText; }
</script>
<span id="notify_using_se"></span>
</div>

The javascript function is called by the on_click event of an option
button but I want to change Text="Seach" of the ASP button to the text
returned by the Function ChangeOptionName(sText)

Thanks in advance for any guide lines :)
Sep 7 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Ken | last post by:
How can I reset the initial form variables that are set with session statements when clicking on a button? I tried this but the function was not called: <?PHP function reset_form($none) {...
2
by: jb | last post by:
Hello, I need to know which button was pressed in the submit , i tried reading the vaule of submit it the validateDate function but it returns 'undefined' value ; I do this in asp all the time, Not...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
4
by: VA | last post by:
I am using a JS library of functions that I include in my web page using the usual <script type="text/javascript" src=...> method Is there a way to automatically call one of my own functions...
9
by: Stefan Mueller | last post by:
I'd like to set a variable called 'FocusIsOn' if a button got the focus. Because my button is dynamically created I do it like xelement = document.createElement("input") xelement.type = "button"...
14
by: Sinity | last post by:
Anyone knows the method/codes to disable the clicked button after first click by using .aspx-- to prevent people to click many time when waiting for the server response. I tried to do this by...
2
by: inventor | last post by:
I'm doing programming for my science prodject, and when I was programming (I'm building an alphebatizer) I ran into this bug: I've got an input box, but no button or output box. so I do some...
8
by: Coleen | last post by:
Yes, I know why would I want to create a back button when there is one on the browser? Because that's what the users want! they want a "Previous" button that they can click from any web page in...
11
by: GaryB | last post by:
Hi Guys, I've been battling with this one for hours - I hope that you can help me! My code modifies the <aon a page, from a standard document link into a link with a tailored onclick event. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.