0
I’m wearing a ListView
to generate buttons according to the IdPassoWorkflow
, and show on the screen the buttons as per image below.
When clicked, I open one dialog
for the user confirms the action, the issue is that the dialog
does not wait for the user’s confirmation and already calls the method lnkGravar_Click
.
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="SistemasRohr.Formulario.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<style type="text/css">
div#dialog
{
display: none;
}
</style>
<script type="text/javascript">
var PassoWorkflow = parseInt(<% =vsIdPassoWorkflow %>);
function CheckConfirm(IdPassoWorkflow) {
if (IdPassoWorkflow == 2) {
jQuery(function() {
jQuery("#EncaminharGestor").dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Sim": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
jQuery(function() {
jQuery("#EncaminharGestor").dialog("open");
});
//return confirm("Encaminhar para o Gestor?");
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="BodyContent" runat="server">
<div id="dialog">
<div class="ui-dialog" id="dialogMes" title="Mensagem">
<p>
Mês <b>De</b> maior que <b>Até</b></p>
</div>
<div class="ui-dialog" id="EncaminharGestor" title="Mensagem">
<p>
Encaminhar para o Gestor</p>
</div>
<div class="ui-dialog" id="dialogDigiteNValido" title="Mensagem">
<p>
Digite um número valido</p>
</div>
</div>
<asp:Panel ID="panFormulario" runat="server">
<table class="Formulario">
<tr>
<td class="Button" colspan="2">
<asp:ListView ID="lvBotoes" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkGravar" OnClick="lnkGravar_Click" runat="server" CssClass="ui-button-icon-primary"
OnClientClick='<%#Eval("IdPassoWorkflow","javascript:return CheckConfirm({0}) ;" )%>'
CommandArgument='<%# Eval("IdPassoWorkflow") %>'>
<%# TextoBotao(Container.DataItem) %></asp:LinkButton>
</ItemTemplate>
</asp:ListView>
</td>
</tr>
</table>
</asp:Panel>
<asp:Label ID="Label1" runat="server"></asp:Label>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WLib.Classes;
using WApp.Classes;
namespace SistemasRohr.Formulario
{
public partial class WebForm1 : PageBase
{
public Int32 vsIdPassoWorkflow = 2;
protected void Page_Load(object sender, EventArgs e)
{
List<PassosWorkflow> passos = new List<PassosWorkflow>();
PassosWorkflow passo1 = new PassosWorkflow()
{
IdPassoWorkflow = 1,
InstrucaoPasso = "Salvar",
};
PassosWorkflow passo2 = new PassosWorkflow()
{
IdPassoWorkflow = 2,
InstrucaoPasso = "Enviar Gestor",
};
PassosWorkflow passo3 = new PassosWorkflow()
{
IdPassoWorkflow = 3,
InstrucaoPasso = "Aprovar",
};
passos.Add(passo1);
passos.Add(passo2);
passos.Add(passo3);
lvBotoes.DataSource = passos;
lvBotoes.DataBind();
}
public String TextoBotao(object o)
{
var Passo = o as PassosWorkflow;
if (Passo == null)
return String.Empty;
return Passo.InstrucaoPasso;
}
protected void lnkGravar_Click(object sender, EventArgs e)
{
Label1.Text = "chamou lnkGravar_Click";
}
}
public class PassosWorkflow
{
public Int32 IdPassoWorkflow { get; set; }
public string InstrucaoPasso { get; set; }
}
}
rendered html of buttons.
<td class="Button" colspan="2">
<a onclick="javascript:return CheckConfirm(1) ;" id="BodyContent_lvBotoes_lnkGravar_0" class="ui-button-icon-primarye" href="javascript:__doPostBack('ctl00$BodyContent$lvBotoes$ctrl0$lnkGravar','')">Salvar</a>
<a onclick="javascript:return CheckConfirm(2) ;" id="BodyContent_lvBotoes_lnkGravar_1" class="ui-button-icon-primarye" href="javascript:__doPostBack('ctl00$BodyContent$lvBotoes$ctrl1$lnkGravar','')">Enviar Gestor</a>
<a onclick="javascript:return CheckConfirm(3) ;" id="BodyContent_lvBotoes_lnkGravar_2" class="ui-button-icon-primarye" href="javascript:__doPostBack('ctl00$BodyContent$lvBotoes$ctrl2$lnkGravar','')">Aprovar</a>
</td>
But in __doPostBack I would call my method normally? because this way is returning the error
Uncaught ReferenceError: lnkGravar is not defined
I switched tolnkGravar_Click
still keeps returning the error.– Marco Souza
In the
__doPostBack
, you pass two parametos, theClientID
ofWebControl
and the arguments... note that I am storing theClienteID
oflnkGravar
at the beginning of the script.– Tobias Mesquita
if you prefer you can use
"OnClick"
as an argument from__doPostBack
:__doPostBack("<%= this.lnkGravar.ClientID %>", "OnClick")
– Tobias Mesquita
This would work if it was just a button, I edited the question with the rendered html of the buttons.
– Marco Souza
@Marconciliosouza, try to pass the
ID
oflnkGravar
as a parameter inCheckConfirm(lnkGravarID, IdPassoWorkflow)
, as followsOnClientClick='<%#Eval("IdPassoWorkflow","javascript:return CheckConfirm(this.id, {0}) ;"
, then call the__doPostBack(lnkGravarID, "OnClick")
– Tobias Mesquita
That way you pass the right id just don’t call the method
protected void lnkGravar_Click(object sender, EventArgs e)
– Marco Souza
Toby, I managed to compliment you by calling
__doPostBack
as follows.__doPostBack('ctl00$BodyContent$lvBotoes$ctrl0$lnkGravar', IdPassoWorkflow);
I had to use thectl00$BodyContent$lvBotoes$ctrl0$lnkGravar
which is the first button created on the screen and passes theIdPassoWorkflow
like how I thought that was what I needed by taking the C this way#var argument = Request.Form["__EVENTARGUMENT"];
, I don’t know if it’s the right one, but it was the solution I found.– Marco Souza
@Marconciliosouza glad it worked.
– Tobias Mesquita