472,347 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,347 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 1928
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...
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...
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...
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...
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 =...
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...
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...
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"...
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.