hello ... i have created dynamically LinkButton, but when i click on it,
the LinkButton_Click method is not invoked???!!!
the codes are as follow in the first page:
LinkButton adtitle = new LinkButton();
adtitle.Text = "Title:" + GridView1.Rows[rowind].Cells[3].Text;
title= GridView1.Rows[rowind].Cells[3].Text;
adtitle.OnClientClick = "adtitle_Click";
adtitle.Click += new EventHandler(this.adtitle_Click);
tcell_3.Controls.Add(adtitle);
trow_3.Controls.Add(tcell_3);
mytable.Controls.Add(trow_3);
this.form2.Controls.Add(adtitle);
and the method is:
private void method_to_call(object sender, EventArgs e)
{
Session["email"] = Email;
Session["title"] = Title1;
Session["message"] = "Ad registered!";
Server.Transfer("adpage.aspx");
}
and in adpage.aspx:
if (Session["email"] != null &&
Session["title"] != null &&
Session["message"] != null)
{
email = Session["email"].ToString();
title = Session["title"].ToString();
insert();
}
else
lblOutput.Text = "something is wrong!";
as you see, in e first webform, i create a table of controls and when i click on linkbutton control,
it should transfer variables into another page (adpage.aspx)...
but when i click, it stands in the same first webform, with no table (!!!?)
and it doesnt goes to adpage.aspx, why???!!!
i tried to put the linkbutton in Page_Load, without any result (the same problem remains).
i dont know, it seems that something is null or empty...
but what? how and with what should i assign it?
p.s. i tried with following codes in first webform, without nay result!!!???
LinkButton adtitle = new LinkButton();
adtitle.Text = "Title:" + GridView1.Rows[rowind].Cells[3].Text;
adtitle.OnClientClick = "adtitle_Click";
adtitle.Click += (sender,args)=>{ _=new EventHandler(this.adtitle_Click);};
tcell_3.Controls.Add(adtitle);
trow_3.Controls.Add(tcell_3);
mytable.Controls.Add(trow_3);
this.form2.Controls.Add(adtitle);
thanks for your respond and kind regards
venus najadPosted Aug 2, 2023, 8:46 PM
i solved my problem bo delete the (y putting the clickable contgrols in Page_Init... they worked very well...
another solution is to delete the if(!IsPostBack) in Page_Load. then it works properly
kind regards
venus najadPosted Aug 2, 2023, 4:58 PM
it seems that the object, i want the click event to be assigned to is NULL.
So there must be something wrong creating it dynamically.
you see the creation of the dynamik control, can you please correct it for me? Thanks and kind regards
venus najadPosted Aug 2, 2023, 6:59 AM
Thanks for your respond... i have tried with different ways, without any result...
because i fill the table whole the time from s gridview, i have made a method... the click works, but it doesnt lauch the click method, Why???!!!
i call to the fill table method in page load and i put a button in page load, without any result...
the open.click or atitle.click works, but it doesnt lauch open_click in open.Click+=this.open_Click
open is the button id...
Its strange... something is empty and i dont know What and how i should assign it and with What i should assign it...
appreciate your respond...
Amit MohantyPosted Aug 2, 2023, 5:41 AM
You attached the event handler to the LinkButton using a lambda expression. The correct way to attach an event handler in C#:
If you are creating the LinkButton dynamically in the first webform, make sure you do it during the appropriate stage of the page lifecycle, such as during Page_Init or Page_Load. If you create the controls too late in the lifecycle, events may not be properly wired up.
Example:
venus najadPosted Aug 1, 2023, 4:35 PM
hello and thanks for your respond... i added old method... i have run with:
private void adtitle_Click(object sender, EventArgs e)
{
Session["email"] = Email;
Session["title"] = Title1;
Session["message"] = "Ad registered!";
Server.Transfer("adpage.aspx");
}
but it remains in the same first page, without the table... it doesnt start private void adtitle_Click(object sender, EventArgs e) at all and i dont know why...
i tried with lamda expression too, without any result... acutally i dont know which codes i should write in lamda... i tried with:
adtitle.Click += (sender,args)=>{ _=new EventHandler(this.adtitle_Click);};
and also this:
adtitle.Click += (sender,args)=>{
Session["email"] = Email;
Session["title"] = Title1;
Session["message"] = "Ad registered!";
Server.Transfer("adpage.aspx");
};
one reason i guess is that i do not use the clickable LinkButton i Page_Load, while i refer to a method for filling my table with a lot of dynamic controls...
i appreciate your respond... kind regards
Amit MohantyPosted Aug 1, 2023, 2:16 PM
In your code, you have named the method method_to_call, but you are subscribing to the event adtitle_Click. Make sure the method name and event name are the same. So, rename your method to adtitle_Click instead of method_to_call.