venus najad

venus najad

  • 1.3k
  • 414
  • 29.1k

dynamically LinkButton_Click or Button_Click are not invoked??!!

Aug 1 2023 12:47 PM

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


Answers (6)