Adding javascript client-side funtionality to a Button webcontrol

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Adding javascript client-side funtionality to a Button webcontrol

    I just learned how to add client-side javascript funtionality to a Button
    Web control by using the Attributes.Add method at run-time.
    myButton.Attributes.Add("onClick", "return confirm('Are you sure about
    this?');")

    But the problem arises when I want to add similar conditional funtionality
    to buttons i a datagrid:
    I have a datagrid in one of my pages where I want one column with buttons. I
    want these buttons to open a new page in a new browser window, passing
    different querystring parameters based on values from the record for the
    specific datagrid-row.
    The client-side attribute for the button in a specific datagrid row should
    be something like:

    onClick="window.open('theotherpage.asp?id=thisreco rdsid&customer=thisrecords
    customer

    Can anyone show an example of how to accomplish this (preferably in VB.Net)?


    Jørn A Guest

  2. Similar Questions and Discussions

    1. Hit Counter in Javascript on client side.
      Have opportunity to use free web server space but can only use client scripting. How to code hit counter in javascript? Any help would be...
    2. JavaScript Access to Button in form tags (webcontrol or html button)
      Hello, I have a button called LoadBtn, which exists in <form name="Form1" runat=server></form> tags. I then have javascript loaded outside of...
    3. Loading client-side images for use in Javascript
      Ok, I'll play the dumb guy.... if your script is running on the server under the testapp application, why isn't the source 'Images/down.gif' (Path...
    4. how can i add client side javascript to a web user control?
      hi, i have a web user control that i wish to add some client-side javascript to. something like this: onChange="javascript:DoSomething();" ...
    5. button evet ---- server side - client side ???
      I want to use button. My question is that How can use server side and client site event at the same time. That is: I want to use button : when...
  3. #2

    Default Re: Adding javascript client-side funtionality to a Button webcontrol


    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <input type="button"
    onclick="window.open('http://www.microsoft.com')" value="xxx" />
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>

    "Jørn A" <nospamwanted@nospam.no> wrote in message
    news:%23BipkGoMEHA.628@TK2MSFTNGP11.phx.gbl...
    > I just learned how to add client-side javascript funtionality to a Button
    > Web control by using the Attributes.Add method at run-time.
    > myButton.Attributes.Add("onClick", "return confirm('Are you sure about
    > this?');")
    >
    > But the problem arises when I want to add similar conditional funtionality
    > to buttons i a datagrid:
    > I have a datagrid in one of my pages where I want one column with buttons.
    I
    > want these buttons to open a new page in a new browser window, passing
    > different querystring parameters based on values from the record for the
    > specific datagrid-row.
    > The client-side attribute for the button in a specific datagrid row should
    > be something like:
    >
    >
    onClick="window.open('theotherpage.asp?id=thisreco rdsid&customer=thisrecords
    > customer
    >
    > Can anyone show an example of how to accomplish this (preferably in
    VB.Net)?
    >
    >

    Michael Tkachev Guest

  4. #3

    Default Re: Adding javascript client-side funtionality to a Button webcontrol

    That's OK, but you did not use a WebControl in your example... I need to use
    a WebControl for the other funtionality in my page. A standard input HTML
    tag won't do.

    I thought of using a HTMLControl (input) instead of a WebControl, but then I
    had a new problem with ASPNET HTML-encoding the content of my onClick event.

    Any more suggestions anyone?

    -Jørn A.

    "Michael Tkachev" <m_tkachev@hotmail.com> wrote in message
    news:ea2y8KpMEHA.2736@TK2MSFTNGP11.phx.gbl...
    >
    > <Columns>
    > <asp:TemplateColumn>
    > <ItemTemplate>
    > <input type="button"
    > onclick="window.open('http://www.microsoft.com')" value="xxx" />
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    >
    > "Jørn A" <nospamwanted@nospam.no> wrote in message
    > news:%23BipkGoMEHA.628@TK2MSFTNGP11.phx.gbl...
    > > I just learned how to add client-side javascript funtionality to a
    Button
    > > Web control by using the Attributes.Add method at run-time.
    > > myButton.Attributes.Add("onClick", "return confirm('Are you sure
    about
    > > this?');")
    > >
    > > But the problem arises when I want to add similar conditional
    funtionality
    > > to buttons i a datagrid:
    > > I have a datagrid in one of my pages where I want one column with
    buttons.
    > I
    > > want these buttons to open a new page in a new browser window, passing
    > > different querystring parameters based on values from the record for the
    > > specific datagrid-row.
    > > The client-side attribute for the button in a specific datagrid row
    should
    > > be something like:
    > >
    > >
    >
    onClick="window.open('theotherpage.asp?id=thisreco rdsid&customer=thisrecords
    > > customer
    > >
    > > Can anyone show an example of how to accomplish this (preferably in
    > VB.Net)?
    > >
    > >
    >
    >

    Jørn A Guest

  5. #4

    Default Re: Adding javascript client-side funtionality to a Button webcontrol

    Private Sub ItemCreated(ByVal Sender As Object, ByVal E As
    DataGridItemEventArgs) Handles Datagrid1.ItemCreated
    Select Case E.Item.ItemType
    Case ListItemType.Item, ListItemType.AlternatingItem,
    ListItemType.SelectedItem
    Dim drv As DataRowView = E.Item.DataItem
    Dim theimagebutton As ImageButton
    theimagebutton = E.Item.FindControl("theimagebutton") 'note
    : theimagebutton is the name of control too...
    theimagebutton.Attributes.Add("onclick",
    "window.open('theotherpage.asp?id= & drv.Item("thisrecordsid") &
    "&customer=" & drv.Item("thisrecordscustomer") & "');")
    End Select
    End Sub

    "Jørn A" <nospamwanted@nospam.no> wrote in message
    news:O8xTPRqMEHA.624@TK2MSFTNGP11.phx.gbl...
    > That's OK, but you did not use a WebControl in your example... I need to
    use
    > a WebControl for the other funtionality in my page. A standard input HTML
    > tag won't do.
    >
    > I thought of using a HTMLControl (input) instead of a WebControl, but then
    I
    > had a new problem with ASPNET HTML-encoding the content of my onClick
    event.
    >
    > Any more suggestions anyone?
    >
    > -Jørn A.
    >
    > "Michael Tkachev" <m_tkachev@hotmail.com> wrote in message
    > news:ea2y8KpMEHA.2736@TK2MSFTNGP11.phx.gbl...
    > >
    > > <Columns>
    > > <asp:TemplateColumn>
    > > <ItemTemplate>
    > > <input type="button"
    > > onclick="window.open('http://www.microsoft.com')" value="xxx" />
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > > </Columns>
    > >
    > > "Jørn A" <nospamwanted@nospam.no> wrote in message
    > > news:%23BipkGoMEHA.628@TK2MSFTNGP11.phx.gbl...
    > > > I just learned how to add client-side javascript funtionality to a
    > Button
    > > > Web control by using the Attributes.Add method at run-time.
    > > > myButton.Attributes.Add("onClick", "return confirm('Are you sure
    > about
    > > > this?');")
    > > >
    > > > But the problem arises when I want to add similar conditional
    > funtionality
    > > > to buttons i a datagrid:
    > > > I have a datagrid in one of my pages where I want one column with
    > buttons.
    > > I
    > > > want these buttons to open a new page in a new browser window, passing
    > > > different querystring parameters based on values from the record for
    the
    > > > specific datagrid-row.
    > > > The client-side attribute for the button in a specific datagrid row
    > should
    > > > be something like:
    > > >
    > > >
    > >
    >
    onClick="window.open('theotherpage.asp?id=thisreco rdsid&customer=thisrecords
    > > > customer
    > > >
    > > > Can anyone show an example of how to accomplish this (preferably in
    > > VB.Net)?
    > > >
    > > >
    > >
    > >
    >
    >

    Benyamin Maengkom Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139