G
Guest
Hi,
I'm having trouble with using !IsPostBack. I want to create a linkbutton
within a table when the page loads the first time and then have the page
redirect based on the LinkButton.CommandArgument string when the LinkButton
is clicked. If I use if(!IsPostBack) as in the following code, the
MyLinkButton_Click is never fired. If I remove the if(!IsPostBack) then when
the LinkButton is clicked the Page_Load is executed (as you would expect) and
after that procedure finishes, the MyLinkButton_Click event fires and the
redirection is successful. Obviously, I don't want the Page_Load to have to
happen for MyLinkButton_Click event to fire. Thanks for any suggestions.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MyNamespace
{
/// <summary>
/// Summary description for test.
/// </summary>
public class MyWebPage: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Table Table1;
private void MyLinkButton_Click(object sender, CommandEventArgs e)
{
string strMyArgument=e.CommandArgument.ToString();
Session.Add("MyArgument", strMyArgument);
Response.Redirect("another_page.aspx");
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack) //MyLinkButton_Click will not fire if this line is
included
{
try
{
TableRow tRow=new TableRow();
TableCell tCell = new TableCell();
string MyString="click here";
LinkButton MyLinkButton = new LinkButton();
MyLinkButton.Command +=new CommandEventHandler(MyLinkButton_Click);
string strCommandArgument = "MyArgument";
MyLinkButton.CommandArgument=strCommandArgument;
MyLinkButton.Text=MyString;
tCell.Controls.Add(MyLinkButton);
tRow.Cells.Add(tCell);
Table1.Rows.Add(tRow);
}
catch
{
}
}
}
I'm having trouble with using !IsPostBack. I want to create a linkbutton
within a table when the page loads the first time and then have the page
redirect based on the LinkButton.CommandArgument string when the LinkButton
is clicked. If I use if(!IsPostBack) as in the following code, the
MyLinkButton_Click is never fired. If I remove the if(!IsPostBack) then when
the LinkButton is clicked the Page_Load is executed (as you would expect) and
after that procedure finishes, the MyLinkButton_Click event fires and the
redirection is successful. Obviously, I don't want the Page_Load to have to
happen for MyLinkButton_Click event to fire. Thanks for any suggestions.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MyNamespace
{
/// <summary>
/// Summary description for test.
/// </summary>
public class MyWebPage: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Table Table1;
private void MyLinkButton_Click(object sender, CommandEventArgs e)
{
string strMyArgument=e.CommandArgument.ToString();
Session.Add("MyArgument", strMyArgument);
Response.Redirect("another_page.aspx");
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack) //MyLinkButton_Click will not fire if this line is
included
{
try
{
TableRow tRow=new TableRow();
TableCell tCell = new TableCell();
string MyString="click here";
LinkButton MyLinkButton = new LinkButton();
MyLinkButton.Command +=new CommandEventHandler(MyLinkButton_Click);
string strCommandArgument = "MyArgument";
MyLinkButton.CommandArgument=strCommandArgument;
MyLinkButton.Text=MyString;
tCell.Controls.Add(MyLinkButton);
tRow.Cells.Add(tCell);
Table1.Rows.Add(tRow);
}
catch
{
}
}
}