Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How events fire in .net

Status
Not open for further replies.

theogary

Programmer
Mar 3, 2003
99
US
I have a aspx page with a grideview. Whe a user click the gridview a usercontrol is loaded. When a user clicks on the run button nothing happens. When the user click on the button again the the button responds and runs the job. Why won't the button respond the first time it is clicked? What can I do to make the button clicked event happen the first time the user clicks the button? Why must I click it twice? I load the user control in the load.postdata event of the aspx...is that the right event?
 
What is the difference between Remove & Clear Control

Here is my code........

this is the user control button c#

protected void Button1_Click(object sender, EventArgs e)
{
ParameterCollection PC = new ParameterCollection();
Parameter par = new Parameter();
par.Name = "effective_date";
par.DefaultValue = TextBox1.Text;

PC.Add(par);
Session["ReportArguments"] = PC;
Server.Transfer("~/Reports/Rpt.aspx");
}


This is my ASPX C#

if (Page.IsPostBack)
{

if (Pickedrow != null )
{
UserControl myControl1 = (UserControl)LoadControl("../UControl/" + Pickedrow);
Param_Panel.Controls.Add(myControl1);
}
}
 
best guess, this is a problem with the dynamic controls and the postback model.

if a control is dynamically loaded it must be loaded every time. also if you depend on viewstate the control must have the ID property assigned.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I have added a ID but the behavior is still the same. The button even fires after 2 clicks. I have tried recreating the object is the init & the pagelaod with same results. I have been pulling out the remaining hair I have left. I have been trying this for a week. Does any have any code or example which demonstrates a button clicked event on a dynamic userobject on a aspx page using C# or VB net. I have a deadline to meet. Please anyone HELP........
 
Does any have any code or example which demonstrates a button clicked event on a dynamic userobject on a aspx page using C# or VB net.
Yes, I created a simple example here:



-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
This example is good but it is not what I am Doing. I am adding a user control with a button on it not just a button. I have several user controls. Each represents report parameters for different reports. When the user select a report from a grid control the report arguments appears as a user control below the grid control . This piece works fine. When the user enters a date and clicks the run button on the user control nothing happens the first time. The second click the report runs. When the user switches to another user control and enters a code and then clicks the run button nothing happens the first time, the second click the report runs. I want this report to run on the first click. I hope this explains my situation. Each user control has unique code to validate and pass different arguments to reports. Any code would be appriciated. This is timing issue. I have assigned a conrol ID to the dynamic control.
 
The principles are the same though. I'd suggest stepping through your code and seeing in what order the page, user control and control events fire. This is known as the page life cycle and this is what you will need to understand to fix your problem.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top