473,662 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting server-side textbox with javascript?

VMI
In the Page_Load() of my webForm, I have the following code, and on my HTML
button, the onclick button calls writeVal() (the javascript function). When
I click on the button, I see the messagebox from the Alert(), but the
server-side Textbox text is not set to 'TEST'. I get a javascript error
saying, "document.getEl ementById(...) is null or is not an object.". What
could the problem be? The textbox is inside a Wizard control. Here's the code:

protected void Page_Load(objec t sender, EventArgs e)
{
string scr2 = @"<script>
function writeVal()
{
alert('test');
document.getEle mentById('txt_n ame').innerText = 'TEST';
}
</script>";
Page.RegisterCl ientScriptBlock ("writeVal", scr2);
}

I can only assume that the Textbox being inside the Wizard could be causing
the error. I'm using VS2005 v2.0

Thanks.

Oct 9 '06 #1
2 2173
"VMI" <VM*@discussion s.microsoft.com wrote in message
news:B3******** *************** ***********@mic rosoft.com...
In the Page_Load() of my webForm, I have the following code, and on my
HTML
button, the onclick button calls writeVal() (the javascript function).
When
I click on the button, I see the messagebox from the Alert(), but the
server-side Textbox text is not set to 'TEST'. I get a javascript error
saying, "document.getEl ementById(...) is null or is not an object.".
What could the problem be? The textbox is inside a Wizard control.
The "problem" is exactly as you describe it - the textbox is inside a Wizard
control, which means that by the time the HTML comes to be rendered to the
browser, the client-side name of the textbox is no longer just txt_name -
it's probably something like the name of your Wizard control plus an
underscore plus "txt_name". Do a View Source and you'll see what I mean.

txt_name.Client ID will tell you the name of the textbox client-side i.e. the
name that the client-side JavaScript will need to reference.
Oct 9 '06 #2
If it's an ASP.Net textbox, keep in mind that the ID that will be given to
it when rendered is not the same ID that you set as it's name. A unique name
will be generated for it by the framework. You should be able to reference
it from the ClientId property such as:

document.getEle mentById('" & txt_name.Client ID & "').innerTe xt = 'TEST';

This should inject the clientid of the text box inside the string. This is
identical to the UniqueID name generated for the control, except the
clientid uses underscores instead of the UniqueID's colons, which can't be
read in javascript.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"VMI" <VM*@discussion s.microsoft.com wrote in message
news:B3******** *************** ***********@mic rosoft.com...
In the Page_Load() of my webForm, I have the following code, and on my
HTML
button, the onclick button calls writeVal() (the javascript function).
When
I click on the button, I see the messagebox from the Alert(), but the
server-side Textbox text is not set to 'TEST'. I get a javascript error
saying, "document.getEl ementById(...) is null or is not an object.". What
could the problem be? The textbox is inside a Wizard control. Here's the
code:

protected void Page_Load(objec t sender, EventArgs e)
{
string scr2 = @"<script>
function writeVal()
{
alert('test');
document.getEle mentById('txt_n ame').innerText = 'TEST';
}
</script>";
Page.RegisterCl ientScriptBlock ("writeVal", scr2);
}

I can only assume that the Textbox being inside the Wizard could be
causing
the error. I'm using VS2005 v2.0

Thanks.

Oct 9 '06 #3

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

Similar topics

3
5288
by: Florian | last post by:
I need to set multiple values for some SQL statements, for example SET NUMERIC_ROUNDABORT OFF GO SET ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_YIELDS_NULL,ARITHABORT,QUOTED_IDENTIF IER,ANSI_NULLS ON GO in a .sql file, but would like to reset them to their previous settings
4
13002
by: Frank Esser | last post by:
I am using SQL 8 Personal edition with sp2 applied. I set the max server memory to 32MB and leave the min server memory at 0. When my application starts hitting the database hard the memory usage reported through task manager peaks between 41-42MB. I've stopped and restarted the MSSQLserver service and checked that the running values are what I set them to be. Does anybody have any ideas as to why the sqlservr.exe would be utilizing more...
1
7071
by: Bob | last post by:
I used Enterprise Manager to change the data type of one table column from one thing to another. When I attempted to save the change, I was warned that "one or more existing columns have ANSI_PADDING 'off' and will be re-created with ANSI_PADDING 'on'". I didn't expect to see this message. I verified that ANSI_PADDING is 'off' at the database level by running the following statement: SELECT DATABASEPROPERTYEX('database',...
2
1722
by: Hardy Wang | last post by:
Hi, We migrated some of web applications to a new server. When the server was installed, the regional setting was EN-CA, later on we found culture display was not same as from original server (which was EN-US), we reset server's culture to EN-US. Now we have 2 web applications still behaviouring as EN-CA setting. It recoginizes string "03/01/2003" as Januray 3rd 2003, not March 1st 2003. I checked code, nothing is wrong. I check regional...
0
1119
by: tshad | last post by:
I am trying to set my radio buttons Programmatically. But no matter what I do - the 3rd one is always checked - even though I can tell my my trace statements the other buttons were the ones set. I have 3 buttons: <asp:RadioButton id="SalaryPerYear" Checked="true" GroupName="SalaryPer" runat="server" text="Year" />&nbsp; <asp:RadioButton id="SalaryPerHour" GroupName="SalaryPer" runat="server" text="Hour"/>&nbsp;
3
1935
by: Patrick | last post by:
I am dynamically creating TextArea and drop-down lists in ASP.NET using something like HtmlTextArea eachTextArea = new HtmlTextArea(); I tried to set the "name" of these TextAreas, etc. (e.g. <textarea name="NameOfTextArea" rows="5" cols="60">some text area</textarea>), as I want to then dynamically read back the controls' values Setting the ID attributes doesn't work, nor does the following:...
0
1784
by: r | last post by:
Hello All, I am working on a desktop application using C#. The application connects to a remote webservice to update and retrieve data from a database. I also have a settings Tab in the application UI that allows the user to enter the proxy server information if needed. When the user selects the "Use Proxy" Checkbox in the settings tab, I ask them to provide the server address and port number and also the login information is...
10
2187
by: Sridhar | last post by:
HI, I am having problems setting up a website so that it will be available only inside the domain. We have three servers. One is iis server and second one is internal server and the third one is sql server. I have deployed the web application in the internal server. It is not able to access the sql server that is on another server. If I deploy the same application on IIS, it is working fine. How should I set up the web application in the...
1
6476
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
6
10046
by: metaperl | last post by:
I would like to check the setting of this variable in our MS-SQL 2000 database. Also, is there info on what the default value of this variable is?
0
8432
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
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8545
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
8633
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
7365
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...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
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.