469,625 Members | 1,904 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

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 1852
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Ken | last post: by
4 posts views Thread by VA | last post: by
14 posts views Thread by Sinity | last post: by
2 posts views Thread by inventor | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.