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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image button in a control

Status
Not open for further replies.

smsinger3

Programmer
Oct 5, 2000
192
US
Hello. I'm new to creating controls in vs.net, so this has to be a dumb question. I created a control with a few dropdown boxes and an image button. When I click the image button, I want to execute code to read the dropdown boxes and do some stuff. I want this code to run BEFORE the Page_Load() on my main page. I put it in several places but they don't seem to work. Here's where I added the code:

1) Sub New() - nothing is really available yet
2) Page_Load(), imgbutton_click() - this works fine, but it runs AFTER the Page_Load in the main page. I want it to run first.
3) imgbutton_load() and imgbutton_init() - My dropdown boxes can't seem to be read here. drpDown1.SelectedItem = -1, but I know it should be a different number.

How can I run the code before the Page_Load in the main page and still read my dropdown boxes????????

Thanks for your help!!!

SteveS
 
Hey Steve,

k, first thing about the Page_Load(): no matter what button you click, and whether its in a user control or on a page, Page_Load() ALWAYS fires. The way around this (if you don't want the code within it to run) is to put the code inside around a If Not page.ispostback Then/End IF construct (this will fire the code within only when the page is first viewed).

Not really sure what the problem with the drop down list is, but keep this in mind: by default, ddl's have their AutoPostBack property set to False, so that may be the issue.

let me know if you're still having some probs

D'Arcy
 
I definately don't want to do the autopostback. Here is the order of my processing that is needed:

1) The user clicks the control on the button.
2) Certain data needs to be written to the database from the control. Basically, it's the data in the dropdown fields that I added to the control.
3) In the Page_Load of the main page, I always want to run some sql statements that uses what I have just put in the database. This will run whether it's the first time in the page or subsequent times because when the page is posted back again, the data in the database may have changed.

Make sense?

What's the best way to do this?
 
I would put the code you now have in page_load into a sub routine. On you page load make a call to that sub within a If Not page.ispostback Then/End IF construct as D'Arcy said. In your button click event after you have done every thing else call that sub to repopulate your control.

This makes things fairly effecient in that the database hit is only occuring when nessecary(sp?). That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Thanks for your responses. I am trying to code Mark's suggestion, but what is the line of code to put in my control ( btn_click() event ) that runs a sub routine in my main page? Keep in mind that the sub routine also uses the Request object and also populates a datagrid control so I need to refer to my actual page
(i.e. I can't code dim x = new MainPage)

Another idea to resolve my problem is to add code to the Page_Load in the main page to check if the button was clicked in the control. But, I have no idea what the line of code is for that? Any suggestions, or is that a bad idea?

Does this make sense. Everyone's help is greatly appreciated! This thing is starting to drive me nuts.

Just a comment: It's a little disappointing that the control can't process it's stuff before the main page. To me, that's one of the main purpose of a control? Then again, I'm new to controls and probably missing something!

 
Before I go off doing alot of typing. Are you using VS or someother product? Also are you using spaggetti code or code behind? That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top