C
C#15mo ago
AideedSS

❔ aspButton need to click twice to trigger the action

my aspButton, whenever I press the button, it doest postback, but the statement code in event doesnt trigger, after the second click, then it trigger the event...this is the code

int totalpage = (int)(ticket_rowItem / 8);
pagediv.InnerHtml = "";
for (int i = 0; i < totalpage; i++)
{
if (ticket_rowItem > 0 && totalpage > 1)
{

LinkButton lbl = new LinkButton();
lbl.Text = "" + (i + 1);
if ((i + 1) == ticket_selectedPage)
{
//pagediv.InnerHtml += "<a href='?page=" + (i + 1) + "' class='btn btn-secondary'>" + (i + 1) + "</a>";
lbl.CssClass = "btn btn-secondary";
}
else
{
//pagediv.InnerHtml += "<a href='?page=" + (i + 1) + "' class='btn btn-light'>" + (i + 1) + "</a>";
lbl.CssClass = "btn btn-light";
}

int m = i;

lbl.Click += (k, l) =>
{
//ticket_selectedPage = (m + 1);
rd.AlertToast(this, "Hello");
};

pagediv.Controls.Add(lbl);
}
}

int totalpage = (int)(ticket_rowItem / 8);
pagediv.InnerHtml = "";
for (int i = 0; i < totalpage; i++)
{
if (ticket_rowItem > 0 && totalpage > 1)
{

LinkButton lbl = new LinkButton();
lbl.Text = "" + (i + 1);
if ((i + 1) == ticket_selectedPage)
{
//pagediv.InnerHtml += "<a href='?page=" + (i + 1) + "' class='btn btn-secondary'>" + (i + 1) + "</a>";
lbl.CssClass = "btn btn-secondary";
}
else
{
//pagediv.InnerHtml += "<a href='?page=" + (i + 1) + "' class='btn btn-light'>" + (i + 1) + "</a>";
lbl.CssClass = "btn btn-light";
}

int m = i;

lbl.Click += (k, l) =>
{
//ticket_selectedPage = (m + 1);
rd.AlertToast(this, "Hello");
};

pagediv.Controls.Add(lbl);
}
}
7 Replies
JakenVeina
JakenVeina15mo ago
what's the context here?
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
AideedSS
AideedSSOP15mo ago
the problem is, why do I have to press the button twice to trigger the event...lets say
btn.Click += (s,e){
Response.Write("hello");
};
btn.Click += (s,e){
Response.Write("hello");
};
I have to click it twice(twice postback) to received hello how to fix this issue?
JakenVeina
JakenVeina15mo ago
you start by giving more context what framework is this? what is "aspButton"? what is that snippet of code you posted, and how does it relate to your question?
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
AideedSS
AideedSSOP15mo ago
ASP.NET framework...sorry for not mention it
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server