By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,432 Members | 790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,432 IT Pros & Developers. It's quick & easy.

I need help with OnPreRender

P: 1
I have a web form in which i use OnPreRender to load controls. it works fine BUT no matter what other events I call, the OnPreRender keeps executing. If I click on one of the buttons to fire off the OnClick event, the OnPreRender runs!!! I don't get it. I've never seen this behaviour before. Does anyone have any ideas???


here's part of the class...



namespace mynamespace
{
/// <summary>
/// Summary description for MyClass.
/// </summary>
public class MyClass : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblQM;
protected System.Web.UI.WebControls.Label lblUsers;
protected System.Web.UI.WebControls.DropDownList ddlUsers;
protected System.Web.UI.WebControls.Label lblSelUser;
protected System.Web.UI.WebControls.Button btnAddUser;
protected System.Web.UI.WebControls.Button btnEditUser;
protected System.Web.UI.WebControls.Button btnDeleteUser;
protected System.Web.UI.WebControls.Label lblFirstName;
protected System.Web.UI.WebControls.Label lblLastName;
protected System.Web.UI.WebControls.Label lblUserName;
protected System.Web.UI.WebControls.Label lblPassword;
protected System.Web.UI.WebControls.Label lblUserProfile;
protected System.Web.UI.WebControls.DropDownList ddlUserProfile;
protected System.Web.UI.WebControls.TextBox tbUserFirstName;
protected System.Web.UI.WebControls.TextBox tbUserLastName;
protected System.Web.UI.WebControls.TextBox tbPassword;
protected System.Web.UI.WebControls.TextBox tbUserName;
protected System.Web.UI.WebControls.Button btnGetUserDetails;
protected System.Web.UI.WebControls.Button btnReturnAdminMain;
protected System.Web.UI.WebControls.Label lblPageTitle;

public MyClass()
{

}

private void Page_Load(object sender, System.EventArgs e)
{
// used to add break point
string debugger = "This is just to debug";
}

protected override void OnPreRender( EventArgs e )
{
string Language = Session["language"].ToString();
if (! Page.IsPostBack)
{
string Language = Session["language"].ToString();
lblPageTitle.Text = Localization.GetString(Language,"administration");
lblQM.Text = Localization.GetString(Language, "lblQM");
lblUsers.Text = Localization.GetString(Language, "lblUsers");
lblSelUser.Text = Localization.GetString(Language, "lblSelUser");
btnAddUser.Text = Localization.GetString(Language, "btnAddUser");
btnEditUser.Text = Localization.GetString(Language, "btnEditUser");
btnDeleteUser.Text = Localization.GetString(Language, "btnDeleteUser");
lblFirstName.Text = Localization.GetString(Language, "lblFirstName");
lblLastName.Text = Localization.GetString(Language, "lblLastName");
lblUserName.Text = Localization.GetString(Language, "username");
lblPassword.Text = Localization.GetString(Language, "password");
lblUserProfile.Text = Localization.GetString(Language, "lblUserProfile");
btnReturnAdminMain.Text = Localization.GetString(Language, "btnReturnAdminMain");
btnGetUserDetails.Text = Localization.GetString(Language, "btnGetUserDetails");
}
}

private void btnGetUserDetails_Click(object sender, System.EventArgs e)
{
string testtheclick = "use to test click with break point";

}
}
}
Aug 8 '07 #1
Share this Question
Share on Google+
1 Reply


nateraaaa
Expert 100+
P: 663
I have a web form in which i use OnPreRender to load controls. it works fine BUT no matter what other events I call, the OnPreRender keeps executing. If I click on one of the buttons to fire off the OnClick event, the OnPreRender runs!!! I don't get it. I've never seen this behaviour before. Does anyone have any ideas???


here's part of the class...



namespace mynamespace
{
/// <summary>
/// Summary description for MyClass.
/// </summary>
public class MyClass : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblQM;
protected System.Web.UI.WebControls.Label lblUsers;
protected System.Web.UI.WebControls.DropDownList ddlUsers;
protected System.Web.UI.WebControls.Label lblSelUser;
protected System.Web.UI.WebControls.Button btnAddUser;
protected System.Web.UI.WebControls.Button btnEditUser;
protected System.Web.UI.WebControls.Button btnDeleteUser;
protected System.Web.UI.WebControls.Label lblFirstName;
protected System.Web.UI.WebControls.Label lblLastName;
protected System.Web.UI.WebControls.Label lblUserName;
protected System.Web.UI.WebControls.Label lblPassword;
protected System.Web.UI.WebControls.Label lblUserProfile;
protected System.Web.UI.WebControls.DropDownList ddlUserProfile;
protected System.Web.UI.WebControls.TextBox tbUserFirstName;
protected System.Web.UI.WebControls.TextBox tbUserLastName;
protected System.Web.UI.WebControls.TextBox tbPassword;
protected System.Web.UI.WebControls.TextBox tbUserName;
protected System.Web.UI.WebControls.Button btnGetUserDetails;
protected System.Web.UI.WebControls.Button btnReturnAdminMain;
protected System.Web.UI.WebControls.Label lblPageTitle;

public MyClass()
{

}

private void Page_Load(object sender, System.EventArgs e)
{
// used to add break point
string debugger = "This is just to debug";
}

protected override void OnPreRender( EventArgs e )
{
string Language = Session["language"].ToString();
if (! Page.IsPostBack)
{
string Language = Session["language"].ToString();
lblPageTitle.Text = Localization.GetString(Language,"administration");
lblQM.Text = Localization.GetString(Language, "lblQM");
lblUsers.Text = Localization.GetString(Language, "lblUsers");
lblSelUser.Text = Localization.GetString(Language, "lblSelUser");
btnAddUser.Text = Localization.GetString(Language, "btnAddUser");
btnEditUser.Text = Localization.GetString(Language, "btnEditUser");
btnDeleteUser.Text = Localization.GetString(Language, "btnDeleteUser");
lblFirstName.Text = Localization.GetString(Language, "lblFirstName");
lblLastName.Text = Localization.GetString(Language, "lblLastName");
lblUserName.Text = Localization.GetString(Language, "username");
lblPassword.Text = Localization.GetString(Language, "password");
lblUserProfile.Text = Localization.GetString(Language, "lblUserProfile");
btnReturnAdminMain.Text = Localization.GetString(Language, "btnReturnAdminMain");
btnGetUserDetails.Text = Localization.GetString(Language, "btnGetUserDetails");
}
}

private void btnGetUserDetails_Click(object sender, System.EventArgs e)
{
string testtheclick = "use to test click with break point";

}
}
}
Try moving your !Page.IsPostBack conditional statement to your Page_Load Event. I would also recommend placing a breakpoint on each of these methods so that you can be sure how your page is behaving. When you click your button the OnPreRenderEvent should fire first, then the Page_Load, and finally the click event of your button.

Nathan
Aug 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.