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

usercontrol works fine in dev environ website, not in prod website

Status
Not open for further replies.

LFCfan

Programmer
Nov 29, 2002
3,015
GB
Hi folks

I have a usercontrol which works fine in my dev environment (which is just a website with one page that has the usercontrol in it).

The usercontrol contains 3 dropdownlists, ddl1, ddl2 and ddl3. When the selected index of ddl1 changes, ddl2 and ddl3 are re-populated from the database, based on the new SelectedValue of ddl1.

This works fine in my dev web page.

When I add this usercontrol to our prod website, selecting a different value in ddl1 doens't change ddl2 and ddl3

It's the exact same code in both cases (I have triple-checked this!) and I'm stumped as to what to look for next

ddl1 doesn't have a OnSelectedIndexChanged event, but causes Postback. In my dev environment, the Response.Write shows the new value of ddl1.

In the website that I need to add the usercontrol to, the Response.Write shows the old value off ddl1

I'm stumped as to what to look for next and appreciate any pointers

Code:
if(!Page.IsPostback)

{

  // do stuff

}

else

{

  Response.Write(ddl1.SelectedValue);

  ddl2.DataSource = GetValsFromDb(ddl1.SelectedValue);

}

~LFCfan

 
do you have the autopostback=true attribute defined on DDL1?

why doesn't DDL1 have a selected index change event? this is the proper place for the logic. a postback can be caused by more than just a drop down selection.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi Jason,

Thanks for your response.

The lack of SelectedIndexChanged was down to the ViewState being disabled on the other two dropdowns (hence their SelectedIndexChanged events would not be called) - I had to incorporate all the relevant logic in Page_Load for them anyway, so I did for ddl1 as well.


I've fixed the problem now. Even with adding a SelectedIndexChanged for ddl1, I still had the same problem.

In the end I used Request.Form[ddl1.UniqueID] to pick up the selected value and preform the relevant query to the database for the other two dropdowns.

I think the reason why the usercontrol was working fine within my dev website and not in my prod website was because in the prod website, usercontrols are dynamically loaded as opposed to simply placed on the page.

I don't quite understand what's happened under the hood, but at least it's working now!

~LFCfan

 
yes, if you're not using viewstate, then request.form[] is the way to go.
I think the reason why the usercontrol was working fine within my dev website and not in my prod website was because in the prod website, usercontrols are dynamically loaded as opposed to simply placed on the page.
this doesn't make any sense. how can you develop locally one way, but deploy the page a different way.

if you are creating contorls at runtime (vs. designtime) the controls should be added in the page.init event. this ensures they go through the proper life cycle stuff.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Jason,

Right - our scenario is rather difficult to explain (and a complete mess at that)

The usercontrols we develop are usually stand-alone little things, hence why I developed this one within an empty dev website (rather than a copy of prod).

Our prod website has its various page elements added at runtime from the database (we have an in-house developed CMS), but inside Page_Load, not Page_Init

Essentially, this CMS was developed by one developer, with no spec to speak of. We can't even call it a project, as it wasn't managed as one. It's turned into a beast, as people kept wanting things added to it, and it is buggy as anything

Unsurprisingly, I've been put off working in ASP.NET and wish to move to the Sql Server world...

Thanks for your help

~LFCfan

 
we all have a project or two like that :)

asp.net isn't the problem. webforms is. it's common for devs to use the 2 intercahanably, but webforms is an overly complex html rendering engine. asp.net just handles the request/response.

another way to look at it: asp.net is the framework that makes monorail, webforms and msmvc possible. webforms is just one option to render html.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
heh, if only it were a mere one or two of our projects that were like that!

And yes, I see your point re: webforms/ASP.NET, but if I'm honest, it's the whole web development aspect of things I'm becoming increasingly annoyed with! I'm a middle/data tier person, methinks :)




~LFCfan

 
I'm a middle/data tier person, methinks :)
then webforms is like nails on a chalk board ;)

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
lol, that's a very good description!

~LFCfan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top