Browser event from webform control

Discussion in 'ASP .Net' started by =?Utf-8?B?QXJuZQ==?=, May 27, 2004.

  1. How do I make a web form control react to a client side event in the browser
    THe onclick event to server based. I am looking for onclick event on the client
    I need something like this from a webform button control
    <input type=button onclick="return OK()>"><script language="javascript"
    function OK(

    return confirm("Delete News Item. OK?")

    </script
    But I need the server event also.
     
    =?Utf-8?B?QXJuZQ==?=, May 27, 2004
    #1
    1. Advertising

  2. Here's some server side code that outputs javascript similar to what you are
    requesting:
    myDeleteButton.Attributes.Add("onclick", _
    "return confirm('Are you sure you want to delete?');")

    In this example, the Delete button will post back only if the person
    confirms they want to delete. Otherwise your server code is never called in
    response to the button click.

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://Steve.Orr.net


    "Arne" <> wrote in message
    news:...
    > How do I make a web form control react to a client side event in the

    browser.
    > THe onclick event to server based. I am looking for onclick event on the

    client.
    > I need something like this from a webform button control:
    > <input type=button onclick="return OK()>"><script language="javascript">
    > function OK()
    > {
    > return confirm("Delete News Item. OK?");
    > }
    > </script>
    > But I need the server event also.
     
    Steve C. Orr [MVP, MCSD], May 27, 2004
    #2
    1. Advertising

  3. Let's say your button tag looks like this:

    <asp:button id="Button1" style="Z-INDEX: 103; LEFT: 62px; POSITION: absolute; TOP: 233px" runat="server"
    Text="Do It"></asp:button>

    Add the following line in the Page_Load procedure:

    Button1.Attributes("OnClick") = "return OK();"

    HTH
     
    =?Utf-8?B?UmljaA==?=, May 27, 2004
    #3
  4. Hi

    Since you are using a regular button ( not submit )

    myBtn.Attributes.Add("onclick","confirmDel(" + iItemID + ")");

    Client
    function confirmDel(iItemID){
    if(confirm("Delete item?")) location.replace("pageToGo.aspx?iItemID=" +
    iItemID);
    // Or if you want submit the form
    //if(confirm("Delete item?")) document.forms[0].submit();
    }

    If you use submit/ image button just return true/false
    function confirmDel(){
    return confirm("Delete item?");
    }

    --
    Best Regards
    Vidar Petursson
    ==============================
    Microsoft Visual: Scripting MVP 2000-2004
    http://www.icysoft.com/
    http://www.deus-x.com/ Instant e-commerce
    http://www.microsoft.com/technet/scriptcenter/
    Playground: http://213.190.104.211/ ( IE 5.5+ only )

    No matter where you go there you are
    ==============================
    "Arne" <> wrote in message
    news:...
    > How do I make a web form control react to a client side event in the
    > browser.
    > THe onclick event to server based. I am looking for onclick event on the
    > client.
    > I need something like this from a webform button control:
    > <input type=button onclick="return OK()>"><script language="javascript">
    > function OK()
    > {
    > return confirm("Delete News Item. OK?");
    > }
    > </script>
    > But I need the server event also.
     
    Vidar Petursson, May 28, 2004
    #4
    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. titof
    Replies:
    0
    Views:
    517
    titof
    Jul 24, 2003
  2. timmso
    Replies:
    1
    Views:
    502
    Alex Papadimoulis
    Dec 12, 2003
  3. =?Utf-8?B?bXN1aw==?=

    Using one webform to set a value on another webform

    =?Utf-8?B?bXN1aw==?=, Jul 12, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    471
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jul 12, 2006
  4. =?Utf-8?B?Vk1J?=

    Moving value from popup Webform to main Webform?

    =?Utf-8?B?Vk1J?=, Oct 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    582
    GroupReader
    Oct 9, 2006
  5. Luqman
    Replies:
    2
    Views:
    668
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Apr 11, 2007
Loading...

Share This Page