473,725 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="textb ox" ID="txtSearch" runat="server"
Width="370px" TabIndex="0" />
<asp:Button ID="cmdDoIt" runat="server" onclick="cmdDoI t" Text="Search"
/>
<script type="text/javascript" language="javas cript">
function ChangeOptionNam e(sText) {
document.getEle mentById("notif y_using_se").in nerHTML = "with " +
sText; }
</script>
<span id="notify_usin g_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 ChangeOptionNam e(sText)

Thanks in advance for any guide lines :)

Sep 6 '08 #1
4 2017
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.comw rote in message
news:5A******** *************** ***********@mic rosoft.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="textb ox" ID="txtSearch" runat="server"
Width="370px" TabIndex="0" />
<asp:Button ID="cmdDoIt" runat="server" onclick="cmdDoI t"
Text="Search" />
<script type="text/javascript" language="javas cript">
function ChangeOptionNam e(sText) {
document.getEle mentById("notif y_using_se").in nerHTML = "with " +
sText; }
</script>
<span id="notify_usin g_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 ChangeOptionNam e(sText)

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

document.getEle mentById("notif y_using_se").in nerHTML = "with " + sText;
document.getEle mentById("<%=cm dDoIt.ClientID% >").value = "with " + sText;
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 6 '08 #3

"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:ur******** ******@TK2MSFTN GP04.phx.gbl...
"Sean" <se**@home.comw rote in message
news:5A******** *************** ***********@mic rosoft.com...
><script type="text/javascript" language="javas cript">

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

>document.getEl ementById("noti fy_using_se").i nnerHTML = "with " + sText;

document.getEle mentById("<%=cm dDoIt.ClientID% >").value = "with " + sText;
Perfect thanks for the help!

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

document.getEle mentById('<%=cm dDoIt.ClientID% >').value = "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="textb ox" ID="txtSearch" runat="server"
Width="370px" TabIndex="0" />
<asp:Button ID="cmdDoIt" runat="server" onclick="cmdDoI t"
Text="Search" />
<script type="text/javascript" language="javas cript">
function ChangeOptionNam e(sText) {
document.getEle mentById("notif y_using_se").in nerHTML = "with " +
sText; }
</script>
<span id="notify_usin g_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 ChangeOptionNam e(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
30108
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) { $_SESSION = array(); } ?> <form enctype="multipart/form-data" name="company_info" method="post" action="add_pic.php">
2
41059
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 sure how to do it in javascript <form name="form1" method="post" action="myNewplace.asp" ONSUBMIT="return ValidateData();"> <input type="Submit" name="Submit" value="Save" >
14
5483
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 that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I have been able to come. I added a little asp.net code and an asp.net button and cannot get it to
4
2211
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 when function foo(...) (from the library) is called? In other words, when foo() is executed, check to see if there is an "execute me also" type of function (associated with foo) defined and if
9
1876
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" element.onfocus = function() {FocusIsOn = "Button_1"; alert(FocusIsOn)} That works great. If the button gets the focus, I got a message box saying 'Button_1'. However, if I set the variable 'FocusIsOn' dynamically (using a variable
14
7187
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 adding a java script for the button. But, useless.. Please help! Thank you
2
498
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 reaserch, insert a button, and when I open it up, instead of the button being added, I lost the input box. Can ANYONE PLEASE HELP ME!!!!!!!!!!!!! I've included a copy of my code as it is: <HTML> <HEAD> Riehl's Alphebatizer <SCRIPT...
8
23234
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 our application that will do the exact same thing as the Back button in the browser. Can anyone give me any suggestions on how to do this using VB .Net? I have Googled for "Create Back Button" and found stuff in JavaScript and HTML but nothing in...
11
3030
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. It works perfectly (assigning the correct images and the correct onclick events to the correct <atags):
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.