Why would this work, but this wont?

shooter69

Expert Member
Joined
Jun 4, 2012
Messages
3,392
Reaction score
943
Location
Dark Africa
Why would this work

protected void Page_Load(object sender, EventArgs e)
{
ucAssign1.ImportID = "2760";
}
But this will not work?

protected void Button1_Click(object sender, EventArgs e)
{
ucAssign1.ImportID = "2760";
}

I need to assign a property in a user control a value upon firing the "Click" event but its not working. Does anyone have a work around?
 
is that method actually connected to the click event of Button1 (ie, if you select the events tab of the button, does it show "onClick Button1_Click" (I assume this is some .net app, and it works pretty much the same as delphi controls )
 
Hi Kabal

Sorry I should have said its a C# asp.net app. Yes the event is connected to the button.

I checked now, some other events also do not fire it off. I don't know if it is a Postback issue.
 
Assuming its a webform can you post the aspx file as well?

Do you have runat="server" on your button and the onclick events etc?

Normally with a usercontrol you have to set up the properties so as to edit the controls in the uc.

public string SetNum
{
get { return setNum.Text; }
set { setNum.Text = value; }
}

If you upload a test app I'm sure someone can fix it for you in a few minutes.
 
Last edited:
Ok I found this now. When clicking on the button the User control gets activated before the event even fires.
The way around it was to create a public method in the control and call the method to do the work.
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X