Hello everyone.
I have just begun using Web User Controls in my Web Forms. The problem I am having is that the contents of the controls take two page load events before ViewState contents are successfully shown in modules as well as WebForm1. I need a way to be able to update all controls with one click in WebUserControl1. Any help will be appreciated. If you need more info, please specify. The code is quite lengthy. As you can see, I did try to Bubble the event from the control to the form. The bubbling works, but the ViewState is not updated until after two clicks. I even tried using a member variable inside WebUserControl1 in place of ViewState, but I get the same result.
Note: When I call the method to update from the click event handler in WebUserControl1, that control is successfully updated, but the rest of controls in WebForm1 are not. They occur the next time the Page Load is called.
I have two custom controls: WebUserControl1 and ShowFilesControl1, both used in WebForm1.
In addition, there is a Label in WebForm1 called lblCurrentPath.
WebUserControl1:
Contains a table with dynamic hyperlink controls that are used for updating the table's contents. Sets and retrieves "Path" information from ViewState: string getCurrPath (), void setCurrPath (string strCurrPath). Contains event handlers that handle click events that update the ViewState.
Main Methods: redrawTable (string path): Clears and repopulates table with updated info based on path. Calls setCurrPath (path). Is called by click event handlers as well as WebForm1's Page Load event.
ShowFilesControl1:
Contains a table with dynamic objects. Table is changed when showFiles (string strPath) method is called.
WebForm1:
using...
namespace webcontrol
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblText;
protected System.Web.UI.WebControls.Label lblCurrentPath;
protected System.Web.UI.WebControls.Button btnSubmit;
protected WebUserControl WebUserControl1;
protected ShowFilesControl ShowFilesControl1;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
WebUserControl1.setCurrPath ("My Computer");
}
loadAll ();
}
protected void loadAll ()
{
WebUserControl1.redrawTable (WebUserControl1.getCurrPath ());
lblCurrentPath.Text = WebUserControl1.getCurrPath ();
ShowFilesControl1.showFiles (WebUserControl1.getCurrPath ());
return;
}
private void WebForm1_BubbleClick(object sender, EventArgs e)
{
Response.Write ("Event successfully registered. <br>");
loadAll ();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
WebUserControl1.BubbleClick += new EventHandler(WebForm1_BubbleClick);
}
#endregion
}
}
I have just begun using Web User Controls in my Web Forms. The problem I am having is that the contents of the controls take two page load events before ViewState contents are successfully shown in modules as well as WebForm1. I need a way to be able to update all controls with one click in WebUserControl1. Any help will be appreciated. If you need more info, please specify. The code is quite lengthy. As you can see, I did try to Bubble the event from the control to the form. The bubbling works, but the ViewState is not updated until after two clicks. I even tried using a member variable inside WebUserControl1 in place of ViewState, but I get the same result.
Note: When I call the method to update from the click event handler in WebUserControl1, that control is successfully updated, but the rest of controls in WebForm1 are not. They occur the next time the Page Load is called.
I have two custom controls: WebUserControl1 and ShowFilesControl1, both used in WebForm1.
In addition, there is a Label in WebForm1 called lblCurrentPath.
WebUserControl1:
Contains a table with dynamic hyperlink controls that are used for updating the table's contents. Sets and retrieves "Path" information from ViewState: string getCurrPath (), void setCurrPath (string strCurrPath). Contains event handlers that handle click events that update the ViewState.
Main Methods: redrawTable (string path): Clears and repopulates table with updated info based on path. Calls setCurrPath (path). Is called by click event handlers as well as WebForm1's Page Load event.
ShowFilesControl1:
Contains a table with dynamic objects. Table is changed when showFiles (string strPath) method is called.
WebForm1:
using...
namespace webcontrol
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblText;
protected System.Web.UI.WebControls.Label lblCurrentPath;
protected System.Web.UI.WebControls.Button btnSubmit;
protected WebUserControl WebUserControl1;
protected ShowFilesControl ShowFilesControl1;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
WebUserControl1.setCurrPath ("My Computer");
}
loadAll ();
}
protected void loadAll ()
{
WebUserControl1.redrawTable (WebUserControl1.getCurrPath ());
lblCurrentPath.Text = WebUserControl1.getCurrPath ();
ShowFilesControl1.showFiles (WebUserControl1.getCurrPath ());
return;
}
private void WebForm1_BubbleClick(object sender, EventArgs e)
{
Response.Write ("Event successfully registered. <br>");
loadAll ();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
WebUserControl1.BubbleClick += new EventHandler(WebForm1_BubbleClick);
}
#endregion
}
}