Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old September 6th, 2008, 04:05 PM
Sean
Guest
 
Posts: n/a
Default 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 :)



  #2  
Old September 6th, 2008, 04:15 PM
Cowboy \(Gregory A. Beamer\)
Guest
 
Posts: n/a
Default Re: Modifying ASP button with javascript variable

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" <sean@home.comwrote in message
news:5AE6275F-78B2-43B3-8E0C-B0882068D740@microsoft.com...
Quote:
>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 :)
>
>
>
  #3  
Old September 6th, 2008, 04:45 PM
Mark Rae [MVP]
Guest
 
Posts: n/a
Default Re: Modifying ASP button with javascript variable

"Sean" <sean@home.comwrote in message
news:5AE6275F-78B2-43B3-8E0C-B0882068D740@microsoft.com...
Quote:
<script type="text/javascript" language="javascript">
You should remove the language tag, as that has been deprecated for quite a
while...

Quote:
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

  #4  
Old September 6th, 2008, 06:35 PM
Sean
Guest
 
Posts: n/a
Default Re: Modifying ASP button with javascript variable


"Mark Rae [MVP]" <mark@markNOSPAMrae.netwrote in message
news:urOiHbDEJHA.5732@TK2MSFTNGP04.phx.gbl...
Quote:
"Sean" <sean@home.comwrote in message
news:5AE6275F-78B2-43B3-8E0C-B0882068D740@microsoft.com...
>
Quote:
><script type="text/javascript" language="javascript">
>
You should remove the language tag, as that has been deprecated for quite
a while...
>
>
Quote:
>document.getElementById("notify_using_se").innerH TML = "with " + sText;
>
document.getElementById("<%=cmdDoIt.ClientID%>").v alue = "with " + sText;
>
Perfect thanks for the help!

  #5  
Old September 7th, 2008, 01:25 AM
bruce barker
Guest
 
Posts: n/a
Default Re: Modifying ASP button with javascript variable

pretty trivial to change the text of a button:

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

-- bruce (sqlwork.com)


Sean wrote:
Quote:
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 :)
>
>
>
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles