473,320 Members | 1,861 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,320 software developers and data experts.

Javascript Interaction with asp.net controls

Hi People,

I have got a simple question to ask. I am trying to build dynamic controls
in asp.net. I have managed to build them successfully. I have also managed to
add the event handlers to all controls I want to monitor. I have the
following code line: -

((CheckBox)ctl).Attributes["onclick"] =
"if(!this.checked){input_box=confirm('All changes to Test will be lost');}";

This is just enabling an action on the check box to be monitored. A
confirmation box props up. Now what I want to do is that if the user selects
ok only then I want to perform the action, but if he presses cancel, then I
do not want to do anything at all. Using this "onclick" thing how can I check
to see what the user selected. Presently it performs the action even if the
user selects cancel.

I hope you guys can help me out.

Much Thanks,

Irfan
Nov 19 '05 #1
7 2101
Irfan,

Are you talking about client or server action? For client action just right
a javascript and call it on onclick event. For server actions you need to
pass an action code from client to server. The most common way of doing this
is using a hidden <input> element.

Eliyahu

"Irfan Akram" <Ir********@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
Hi People,

I have got a simple question to ask. I am trying to build dynamic controls
in asp.net. I have managed to build them successfully. I have also managed to add the event handlers to all controls I want to monitor. I have the
following code line: -

((CheckBox)ctl).Attributes["onclick"] =
"if(!this.checked){input_box=confirm('All changes to Test will be lost');}";
This is just enabling an action on the check box to be monitored. A
confirmation box props up. Now what I want to do is that if the user selects ok only then I want to perform the action, but if he presses cancel, then I do not want to do anything at all. Using this "onclick" thing how can I check to see what the user selected. Presently it performs the action even if the user selects cancel.

I hope you guys can help me out.

Much Thanks,

Irfan

Nov 19 '05 #2
I might be out in left field here...I'm not totally sure what you're wanting
to do...

Why can you not just check yourCheckBox.Checked at the server side?
"Irfan Akram" <Ir********@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
Hi People,

I have got a simple question to ask. I am trying to build dynamic controls
in asp.net. I have managed to build them successfully. I have also managed to add the event handlers to all controls I want to monitor. I have the
following code line: -

((CheckBox)ctl).Attributes["onclick"] =
"if(!this.checked){input_box=confirm('All changes to Test will be lost');}";
This is just enabling an action on the check box to be monitored. A
confirmation box props up. Now what I want to do is that if the user selects ok only then I want to perform the action, but if he presses cancel, then I do not want to do anything at all. Using this "onclick" thing how can I check to see what the user selected. Presently it performs the action even if the user selects cancel.

I hope you guys can help me out.

Much Thanks,

Irfan

Nov 19 '05 #3
Hi Goldin,

First of all thank you for your response. You said in your answer "just right
a javascript and call it on onclick event". Do we write the code in c# or
actual javascript, if javascript then won't the compiler complain ? If in
javascript then how do we reference the c# variables in the javascript code ?

Many thanks,

Irfan

"Eliyahu Goldin" wrote:
Irfan,

Are you talking about client or server action? For client action just right
a javascript and call it on onclick event. For server actions you need to
pass an action code from client to server. The most common way of doing this
is using a hidden <input> element.

Eliyahu


Nov 19 '05 #4
Hi David,

What I'm trying to do eventually is that if the user deselects any of the
check boxes, then there should a pop-up message to confirm the users action.
Only if the user selects yes, then the event happens, not otherwise. You see
to display the pop-up confirmation box i need to use javascript i.e.

((CheckBox)ctl).Attributes["onclick"] =
"if(!this.checked){input_box=confirm('All changes to Test will be lost');}";

Now the question is, how to get what the user selected back in to my c# code.

Hope you understand what i'm trying to say...

Will wait for your response....

Thanks,

Irfan

"David Jessee" wrote:
I might be out in left field here...I'm not totally sure what you're wanting
to do...

Why can you not just check yourCheckBox.Checked at the server side?
"Irfan Akram" <Ir********@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
Hi People,

I have got a simple question to ask. I am trying to build dynamic controls
in asp.net. I have managed to build them successfully. I have also managed

to
add the event handlers to all controls I want to monitor. I have the
following code line: -

((CheckBox)ctl).Attributes["onclick"] =
"if(!this.checked){input_box=confirm('All changes to Test will be

lost');}";

This is just enabling an action on the check box to be monitored. A
confirmation box props up. Now what I want to do is that if the user

selects
ok only then I want to perform the action, but if he presses cancel, then

I
do not want to do anything at all. Using this "onclick" thing how can I

check
to see what the user selected. Presently it performs the action even if

the
user selects cancel.

I hope you guys can help me out.

Much Thanks,

Irfan


Nov 19 '05 #5
Irfan,

Client side doesn't know any c#, only javascript. You can write it in aspx
page. Compiler won't complain since compiler compiles server code. Client
javascript can't reference server c# variables. It can pass information to
server side, where you read it in c# code. When working in asp.net, you have
to understand clearly what's going on the server and what on the client.

Eliyahu

"Irfan Akram" <Ir********@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
Hi Goldin,

First of all thank you for your response. You said in your answer "just right a javascript and call it on onclick event". Do we write the code in c# or
actual javascript, if javascript then won't the compiler complain ? If in
javascript then how do we reference the c# variables in the javascript code ?
Many thanks,

Irfan

"Eliyahu Goldin" wrote:
Irfan,

Are you talking about client or server action? For client action just right a javascript and call it on onclick event. For server actions you need to pass an action code from client to server. The most common way of doing this is using a hidden <input> element.

Eliyahu

Nov 19 '05 #6
The the user checks the checkbox, then if they click yes, you want the
ASP.NET postback to happen (Complete with the checkbox's event handler), and
if they click no, you don't want the postback to happen?
"Irfan Akram" <Ir********@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
Hi David,

What I'm trying to do eventually is that if the user deselects any of the
check boxes, then there should a pop-up message to confirm the users action. Only if the user selects yes, then the event happens, not otherwise. You see to display the pop-up confirmation box i need to use javascript i.e.

((CheckBox)ctl).Attributes["onclick"] =
"if(!this.checked){input_box=confirm('All changes to Test will be lost');}";
Now the question is, how to get what the user selected back in to my c# code.
Hope you understand what i'm trying to say...

Will wait for your response....

Thanks,

Irfan

"David Jessee" wrote:
I might be out in left field here...I'm not totally sure what you're wanting to do...

Why can you not just check yourCheckBox.Checked at the server side?
"Irfan Akram" <Ir********@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
Hi People,

I have got a simple question to ask. I am trying to build dynamic controls in asp.net. I have managed to build them successfully. I have also
managed to
add the event handlers to all controls I want to monitor. I have the
following code line: -

((CheckBox)ctl).Attributes["onclick"] =
"if(!this.checked){input_box=confirm('All changes to Test will be

lost');}";

This is just enabling an action on the check box to be monitored. A
confirmation box props up. Now what I want to do is that if the user

selects
ok only then I want to perform the action, but if he presses cancel,
then I
do not want to do anything at all. Using this "onclick" thing how can
I check
to see what the user selected. Presently it performs the action even
if the
user selects cancel.

I hope you guys can help me out.

Much Thanks,

Irfan


Nov 19 '05 #7
WJ
This google site may be of your interest:
http://msmvps.com/jonathangreensted/.../24/20495.aspx

John
Nov 19 '05 #8

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

Similar topics

53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
6
by: KKramsch | last post by:
OK, here's the scenario: I have a CGI script that generates a page with frames (BTW, I'm not crazy about frames, but in this case the decision to use them is out of my hands). In a typical...
21
by: strutsng | last post by:
<input type="file"> only allows the user to browse for files. How about "browse for folder" dialog? Can html/javascript do that? I couldn't find any syntax for that. If not, please advise what...
3
by: Aaron Queenan | last post by:
I have a form which performs some asynchronous code. I want to display a wait cursor when it starts, and hide the wait cursor when it has completed. This part works fairly well, using: ...
0
by: David Virgil Hobbs | last post by:
While studying the asp.net javascript problem I saw and used pages about asp.net basics at http://www.sitepoint.com/article/815/4 and...
2
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app...
10
by: jason_box | last post by:
Hello, I was wondering if there was a way to have a javacript be activated by an input button that would call to a cgi program and querey every 10minutes and the cgi would update the page without...
6
by: drec | last post by:
I am just learning Javascript and I would like to create a basic form that gives me two options. This will be using either checkbox or radio input type, however I would like the second option to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.