Javascript Interaction with asp.net controls

Discussion in 'ASP .Net' started by =?Utf-8?B?SXJmYW4gQWtyYW0=?=, Jan 16, 2005.

  1. 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
    =?Utf-8?B?SXJmYW4gQWtyYW0=?=, Jan 16, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    Eliyahu Goldin, Jan 16, 2005
    #2
    1. Advertising

  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
    =?Utf-8?B?SXJmYW4gQWtyYW0=?=, Jan 16, 2005
    #3
  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" <> wrote in message
    > news:...
    > > 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

    >
    >
    >
    =?Utf-8?B?SXJmYW4gQWtyYW0=?=, Jan 16, 2005
    #4
  5. =?Utf-8?B?SXJmYW4gQWtyYW0=?=

    David Jessee Guest

    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" <> wrote in message
    news:...
    > 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
    David Jessee, Jan 16, 2005
    #5
  6. 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" <> wrote in message
    news:...
    > 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

    >
    Eliyahu Goldin, Jan 16, 2005
    #6
  7. =?Utf-8?B?SXJmYW4gQWtyYW0=?=

    David Jessee Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > > news:...
    > > > 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

    > >
    > >
    > >
    David Jessee, Jan 16, 2005
    #7
  8. =?Utf-8?B?SXJmYW4gQWtyYW0=?=

    WJ Guest

    WJ, Jan 17, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Virgil Hobbs
    Replies:
    0
    Views:
    500
    David Virgil Hobbs
    Jan 6, 2004
  2. goalizx Goalizx

    Interaction between User Controls

    goalizx Goalizx, Sep 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    453
  3. Lukas Kurka

    Interaction between user controls

    Lukas Kurka, Nov 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    401
    Lukas Kurka
    Nov 23, 2006
  4. Jonas

    Interaction between user controls?

    Jonas, May 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    178
    Michael Tkachev
    May 7, 2004
  5. Weston Weems

    Server Controls and Client Script interaction

    Weston Weems, Dec 1, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    91
    Weston Weems
    Dec 1, 2004
Loading...

Share This Page