Hi all,
I´ve created a web user control (.ascx) which is dynamically added to the page. It contains a RadAjaxPanel which contains a RadGrid, as follows:
And the .CS for this file is as follows:
Well, the ItemCommand event is not firing, even when "btnExcluir" (the ImageButton) is clicked. What am I doing wrong?
Thanks in advance!
I´ve created a web user control (.ascx) which is dynamically added to the page. It contains a RadAjaxPanel which contains a RadGrid, as follows:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ComentarioLista.ascx.cs"
Inherits="Include_RedeSocial20_MuralItem_ComentarioLista" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Src="../../Investidor/Foto.ascx" TagName="Foto" TagPrefix="uc1" %>
<%@ Register Src="ComentarioItem.ascx" TagName="ComentarioItem" TagPrefix="uc2" %>
<%@ Register Src="../../Mensagem.ascx" TagName="Mensagem" TagPrefix="uc3" %>
<
telerik:RadAjaxPanel
ID
=
"RadAjaxPanel1"
runat
=
"server"
HorizontalAlign
=
"NotSet"
>
<
table
style
=
"width: 100%;"
>
<
tr
>
<
td
>
<
asp:LinkButton
ID
=
"btnComentar"
runat
=
"server"
OnClick
=
"btnComentar_Click"
>Comentar</
asp:LinkButton
>
</
td
>
</
tr
>
<
tr
runat
=
"server"
id
=
"trNovoComentario"
visible
=
"false"
>
<
td
>
<
asp:TextBox
ID
=
"tbComentario"
runat
=
"server"
MaxLength
=
"2000"
TextMode
=
"MultiLine"
Width
=
"100%"
></
asp:TextBox
>
<
br
/>
<
asp:Button
ID
=
"btnPostar"
runat
=
"server"
Text
=
"Postar comentário"
CssClass
=
"btnLaranja"
OnClick
=
"btnPostar_Click"
/>
</
td
>
</
tr
>
<
tr
>
<
td
>
<
telerik:RadGrid
ID
=
"RadGridLista"
runat
=
"server"
AutoGenerateColumns
=
"False"
border
=
"1"
GridLines
=
"None"
OnItemCreated
=
"RadGridLista_ItemCreated"
PageSize
=
"10"
SkinID
=
"RadGridForum"
OnItemCommand
=
"RadGridLista_ItemCommand"
>
<
ClientSettings
EnableAlternatingItems
=
"true"
EnableRowHoverStyle
=
"false"
>
</
ClientSettings
>
<
PagerStyle
SEOPagingQueryStringKey
=
"page"
/>
<
MasterTableView
AllowPaging
=
"true"
CellSpacing
=
"-1"
NoMasterRecordsText
=
"Nenhum comentário"
ShowHeader
=
"False"
>
<
RowIndicatorColumn
>
<
HeaderStyle
Width
=
"20px"
/>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
>
<
HeaderStyle
Width
=
"20px"
/>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"CODIGO"
>
<
ItemTemplate
>
<
uc2:ComentarioItem
ID
=
"ComentarioItem1"
runat
=
"server"
Codigo='<%#Eval("CODIGO") %>'
DthrInclusao='<%#Eval("DTHR_INCLUSAO") %>' FotoUrl='<%#Eval("FOTO_URL") %>' PublicacaoCodigo='<%#Eval("SLN_PUBL_CODIGO") %>'
Texto='<%#Eval("TEXTO") %>' UsuarioCodigo='<%#Eval("SLN_USUA_CODIGO") %>' UsuarioCodigoPublicacao='<%#Eval("SLN_USUA_CODIGO_AUTOR") %>'
UsuarioNome='<%#Eval("SLN_USUA_NOME") %>' />
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"EXCLUIR"
HeaderStyle-Width
=
"18px"
>
<
ItemTemplate
>
<
div
align
=
"center"
>
<
asp:ImageButton
ID
=
"btnExcluir"
runat
=
"server"
ImageUrl
=
"~/Images/Botao/excluir2.gif"
CommandArgument='<%#Eval("CODIGO") %>' CommandName="Excluir" Visible='<%#GetVisible(Eval("SLN_USUA_CODIGO").ToString(),Eval("SLN_USUA_CODIGO_AUTOR").ToString()) %>' />
</
div
>
</
ItemTemplate
>
<
HeaderStyle
Width
=
"18px"
/>
</
telerik:GridTemplateColumn
>
</
Columns
>
<
PagerStyle
Position
=
"Bottom"
/>
</
MasterTableView
>
</
telerik:RadGrid
>
</
td
>
</
tr
>
</
table
>
</
telerik:RadAjaxPanel
>
<
uc3:Mensagem
ID
=
"Mensagem1"
runat
=
"server"
/>
<
input
type
=
"hidden"
runat
=
"server"
id
=
"tbPublicacaoCodigo"
/>
And the .CS for this file is as follows:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
using
System.Data.SqlClient;
public
partial
class
Include_RedeSocial20_MuralItem_ComentarioLista : System.Web.UI.UserControl
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
public
Nullable<
decimal
> PublicacaoCodigo
{
get
{
decimal
cod;
bool
isCodValido =
decimal
.TryParse(tbPublicacaoCodigo.Value,
out
cod);
if
(!isCodValido)
return
null
;
else
return
cod;
}
set
{ tbPublicacaoCodigo.Value = value.ToString(); }
}
public
void
BuscaDados()
{
UsuarioDataSetTableAdapters.SLN_VW_PUBLICACAO_COMENTARIOTableAdapter ta =
new
UsuarioDataSetTableAdapters.SLN_VW_PUBLICACAO_COMENTARIOTableAdapter();
UsuarioDataSet.SLN_VW_PUBLICACAO_COMENTARIODataTable dt =
new
UsuarioDataSet.SLN_VW_PUBLICACAO_COMENTARIODataTable();
dt = ta.GetDataByPublicacao((
decimal
)PublicacaoCodigo);
if
(dt.Count == 0)
{
RadGridLista.Visible =
false
;
}
else
{
RadGridLista.Visible =
true
;
RadGridLista.DataSource = dt;
RadGridLista.DataBind();
}
}
protected
bool
GetVisible(
string
usuarioCodigo,
string
usuarioCodigoPublicacao)
{
if
((usuarioCodigoPublicacao.Equals(Sln.Usuario.Usuario.CodigoSessao)) || (usuarioCodigo.Equals(Sln.Usuario.Usuario.CodigoSessao)))
return
true
;
else
return
false
;
}
protected
void
RadGridLista_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridPagerItem)
{
Util.EscondeGridPageSize((GridPagerItem)e.Item);
}
}
protected
void
btnPostar_Click(
object
sender, EventArgs e)
{
SqlTransaction tran =
null
;
try
{
if
(
string
.IsNullOrEmpty(tbComentario.Text))
{
//Page.ClientScript.RegisterStartupScript(Page.GetType(), "aviso", "alert('Comentário não pode ser vazio.');");
RadAjaxPanel1.ResponseScripts.Add(
"alert('Comentário não pode ser vazio.');"
);
return
;
}
// Pega o código da publicação
decimal
pub = PublicacaoCodigo.Value;
UsuarioDataSetTableAdapters.SLN_PUBLICACAO_COMENTARIOTableAdapter ta =
new
UsuarioDataSetTableAdapters.SLN_PUBLICACAO_COMENTARIOTableAdapter();
tran = TableAdapterHelper.BeginTransaction(ta);
decimal
cod = (
decimal
)ta.ProximoCodigo();
ta.Insert(cod, pub, Sln.Usuario.Usuario.CodigoSessao, tbComentario.Text, DateTime.Now);
tran.Commit();
//Response.Redirect(Request.Url.ToString(), false);
tbComentario.Text =
""
;
trNovoComentario.Visible =
false
;
BuscaDados();
}
catch
(Exception ex)
{
if
(tran !=
null
)
tran.Rollback();
if
(ex.Message.ToLower().IndexOf(
"a potentially dangerous"
) >= 0)
Page.ClientScript.RegisterStartupScript(Page.GetType(),
"aviso"
,
"alert('Dangerous text');"
);
else
{
Log.Insere(
string
.Format(
"RedeSocial20.ComentarioLista.Inserir - Usuario: {0} Publicacao: {1} Mensagem: {2} Erro: {3} Trace: {4}"
,
Sln.Usuario.Usuario.CodigoSessao, PublicacaoCodigo, tbComentario.Text, ex.Message, ex.StackTrace), Log.ERROR);
Mensagem1.Exibe(
"Desculpe-nos, houve um erro que será analisado por nossa equipe."
,
false
);
}
}
finally
{
if
(tran !=
null
)
tran.Dispose();
}
}
protected
void
btnComentar_Click(
object
sender, EventArgs e)
{
if
(!trNovoComentario.Visible)
trNovoComentario.Visible =
true
;
else
trNovoComentario.Visible =
false
;
}
protected
void
RadGridLista_ItemCommand(
object
source, GridCommandEventArgs e)
{
string
strCod = e.CommandArgument.ToString();
decimal
codigo =
decimal
.Parse(strCod);
if
(e.CommandName.Equals(
"Excluir"
))
{
// Efetua exclusão do item e então atualiza lista de comentários
UsuarioDataSetTableAdapters.SLN_PUBLICACAO_COMENTARIOTableAdapter taCom =
new
UsuarioDataSetTableAdapters.SLN_PUBLICACAO_COMENTARIOTableAdapter();
taCom.Delete(codigo);
//RadGridLista.Rebind();
BuscaDados();
}
}
}
Well, the ItemCommand event is not firing, even when "btnExcluir" (the ImageButton) is clicked. What am I doing wrong?
Thanks in advance!