Need help with a custom control and a datagrid

Discussion in 'ASP .Net Web Controls' started by Luis Alonso, Oct 12, 2004.

  1. Luis Alonso

    Luis Alonso Guest

    Hi,
    I had created a web custom control to ask for user' confirmation on deleting
    and others process. I put the control in a vb file.
    The control is really simple: only an image button and a hidden panel to
    show a wait message....
    The control has a PreRender (with a RegsiterClientScriptBlock) event and a
    Render event (that writes the control)
    I put the control on a datagrid.
    The control asks confirmation fine and I'm able to retrieve (in
    ItemDataBound, por example) the control, to make it enabled or not, to show
    it or not.
    The problem is that the control does not launch the ItemCommand event in the
    datagrid. So I'm not able to process the request after the user'
    confirmation.
    This is what I have done so far:

    'vb: GridControls
    Namespace GridControls
    public class ctrConfirmButton
    public ConfirmMessage as string =""
    public CommandName as string = ""
    public Imagen as string = ""
    public ToolTip as string = ""
    public Enabled as boolean = False

    protected overrides sub OnPreRender(ByVal e As System.EventArgs)
    dim sScript as string = "" _
    "<script language='javascript'>" & _
    "function __" & me.id & "_doConfirm() {" & _
    "if (confirm('" & ConfirmMessage & "')) {return true;}
    return false; }" & _
    "</script>"

    page.RegsiterClientScriptBlock("__" & me.id & "_doConfirm",
    sScript)
    myBase.OnPreRender(e)
    end sub

    protected overrides sub Render(ByVal writer as
    System.Web.UI.HtmlTextWriter)
    dim sDisabled as string = "disabled='disabled' "

    if Enabled then sDisabled = ""

    writer.write("<input type='image' id= '" & me.id & "_" &
    CommandName & "' title= '" & ToolTip & "' src='" & Imagen & "' alt=''
    border='0' " _
    sDisabled & _
    "onclick='return __" & me.id & "_doConfirm();' >"
    end sub
    end class
    end namespace

    'Page
    <%@ Register TagPrefix= "CtrlsGrid" NameSpace="ControlsProj:GridControls"
    Assably="ControlsProj" %>

    '.....

    <asp:templatecolumn>
    <CtrlsGrid:ctrConfirmButton runat="server"
    id="MyID"
    CommandName="Delete"
    ConfirmMessage="The message"
    Image="Iconos/..."
    ToolTip="The Tooltip"
    Enabled="True"
    >

    </CtrlsGrid:ctrConfirmButton>
    </asp:templatecolumn>

    'Codebehind
    private sub MyItemDataBound(ByVal Sender as object, e as
    system.web.ui.webcontrols.DataGridItemEventArgs) Handles
    DataGrid1.ItemDataBound
    select case e.item.ItemType
    case ListItemType.Item
    dim myControl as ControlsProj.GridControls.ctrConfirmButton =
    ctype(e.item.FindControl("MyID"),
    ControlsProj.GridControls.ctrConfirmButton)
    if not myControl is nothing then myControl .Enabled = True
    case ListItemType.AlternatingiItem
    dim myControl as ControlsProj.GridControls.ctrConfirmButton =
    ctype(e.item.FindControl("MyID"),
    ControlsProj.GridControls.ctrConfirmButton)
    if not myControl is nothing then myControl .Enabled = False
    end select
    end sub

    private sub MyItemCommand(ByVal Sender as object, e as
    system.web.ui.webcontrols.DataGridCommanEventArgs) handles
    DataGrid1.ItemCommad
    me.DataGrid1.DataBind()
    end sub


    The last sub is not getting launch. There is something that I'm missing and
    I cannot make a connection between the datagrid and the control.

    THX, in advance
    Luis Alonso
    Luis Alonso, Oct 12, 2004
    #1
    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. Jonah Olsson
    Replies:
    1
    Views:
    559
    Scott Allen
    Apr 5, 2005
  2. J R M
    Replies:
    2
    Views:
    411
    Charlie@CBFC
    Jun 1, 2006
  3. Matt Sokol
    Replies:
    2
    Views:
    355
    Theo Tillotson
    Aug 7, 2003
  4. dave
    Replies:
    0
    Views:
    90
  5. Jonah Olsson
    Replies:
    2
    Views:
    182
    Jonah Olsson
    Apr 5, 2005
Loading...

Share This Page