By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

Javascript Interaction with asp.net controls

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
WJ
This google site may be of your interest:
http://msmvps.com/jonathangreensted/.../24/20495.aspx

John
Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.