Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Need help with a custom control and a datagrid (http://www.velocityreviews.com/forums/t774468-need-help-with-a-custom-control-and-a-datagrid.html)

Luis Alonso 10-12-2004 06:55 PM

Need help with a custom control and a datagrid
 
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

















All times are GMT. The time now is 07:56 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.