473,386 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

HELP! JavaScript not working through c# code

I have a piece of c# code in the Page_Load function.

submitButton.Attributes.Add("onClick", "return checkForm('" + this +
"','" + SomeTextBox.Text + "')");

When I click the submitButton, it calls the javascript function, but
the value is not being passed....

I cannot find a work around.

Thanks in advance

Nov 19 '05 #1
4 1472
"this," in the context of your code, is a reference to the page class.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Complex things are made up of
Lots of simple things.

<de*****@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have a piece of c# code in the Page_Load function.

submitButton.Attributes.Add("onClick", "return checkForm('" + this +
"','" + SomeTextBox.Text + "')");

When I click the submitButton, it calls the javascript function, but
the value is not being passed....

I cannot find a work around.

Thanks in advance

Nov 19 '05 #2
Hi,

I don't think you need the single-quotes around -this-, should be (this,
'textvalue');. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

<de*****@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have a piece of c# code in the Page_Load function.

submitButton.Attributes.Add("onClick", "return checkForm('" + this +
"','" + SomeTextBox.Text + "')");

When I click the submitButton, it calls the javascript function, but
the value is not being passed....

I cannot find a work around.

Thanks in advance

Nov 19 '05 #3
What value isn't passed?

Are you trying to pass the value in the textbox to this function?
SomeTextBox.Text is being evaluated on the server at the time you are adding
this call. So whatever is in there that moment will be hard coded to get
passed to the function. It's not like VB.NET somehow knows that you want the
client side javascript to evalue the input control with the id of
SomeTextBox and pass its value on to the function.

Unless you were trying to do something else. But if you have to be specific
in your questions if you want a helpful response.

<de*****@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have a piece of c# code in the Page_Load function.

submitButton.Attributes.Add("onClick", "return checkForm('" + this +
"','" + SomeTextBox.Text + "')");

When I click the submitButton, it calls the javascript function, but
the value is not being passed....

I cannot find a work around.

Thanks in advance

Nov 19 '05 #4
I'ts hard to tell what exactly you're adding to the "onclick" attribute of
the submit button, but I would guess that it is adding a client-side script
call for validation to it.

The string you are adding is

"return checkForm{'" + this + "','" + SomeTextBox.Text + "')"

The reference to "this" (without quotes) is a reference to the Page class
itself. Apparently, you're not working in Visual Studio.Net, because it
would give you a compile-time exception, as a Page class is not a string.

As I don't know what it is you want to concatenate into the string by
referencing "this," I can only guess, and I hate to guess.

But, if I were to guess, I would suppose that you really want to put the
string literal "this" (which is often used in JavaScript function calls to
pass a reference to the element that called the function) in your code. If
so, there is no concatenation required:

"return checkForm{'this','" + SomeTextBox.Text + "')"

Of course, this is *still* wrong, as it is not passing a reference to the
element, but the literal string "this" to the function. To pass a reference
to the element, you would need to remove the single quotes:

"return checkForm{this,'" + SomeTextBox.Text + "')"

Of course, this is probably not what you need either. For most client-side
form validation, a reference to the *form* is passed. Passing a reference to
a submit button would be generally pointless.

So, again, presuming that you *do* want to pass a reference to the form
itself to the function, this would have to be modified as follows:

"return checkForm{this.form,'" + SomeTextBox.Text + "')"

ASP.Net is all about HTML, JavaScript, CSS, and client-side technologies.
So, you have 2 skillsets to master:

1.Client-side document technologies (as mentioned above)
2. Server-side .Net programming technology

It is important that you understand both fully, or you will constantly be
plagued with this sort of issue. The Microsoft MSDN Library online is full
of information about both .Net and Internet programming technologies in
general (including HTML, DHTML, JavaScript, CSS, XML, etc). You can find it
at:

http://msdn.microsoft.com

I spend an hour or 2 a day studying this reference on average. And I've been
a developer for about a dozen years.

The nice thing is, you don't have to know it all to do it all. You just have
to know where to find a definitive answer. And if you bookmark the MSDN
Library, you will be well on your way.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
There's a seeker born every minute.
- Dr. "Happy" Harry Cox

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl...
"this," in the context of your code, is a reference to the page class.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Complex things are made up of
Lots of simple things.

<de*****@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have a piece of c# code in the Page_Load function.

submitButton.Attributes.Add("onClick", "return checkForm('" + this +
"','" + SomeTextBox.Text + "')");

When I click the submitButton, it calls the javascript function, but
the value is not being passed....

I cannot find a work around.

Thanks in advance


Nov 19 '05 #5

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

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
2
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
0
by: tbatwork828 | last post by:
If you were like me trying to figure out how to launch context sensitive help topic by the context id, here is the link: http://weblogs.asp.net/kencox/archive/2004/09/12/228349.aspx and if...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
9
by: JJ | last post by:
Do you all use HTML help workshop to create your help system. I am finding it quite clumsy to use. Mayeb because I am not used to using it. Do any of you use any other techniques to create help...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...

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.