收录日期:2020/12/05 23:27:01 时间:2010-09-07 20:37:45 标签:javascript,asp.net,asp.net-mvc,vb.net,sql-server-2005

So I have an .aspx page loading up and populating drop downs based on a lookup table in the database. What we want is for the user to be able to configure which of these values comes defaulted by specifying that value in a drop down somewhere else in the app.

Now, it's easy to default the "first" value, or something like that, but we want this to act differently. Is there a JavaScript function that can run immediately after onLoad (so the drop downs are populated already), that can go through the drop down and make one of those default so it looks like the page is loading with that set as default and people don't realize the workaround? (weird masking, etc.)

I'm not TOO experienced with JavaScript so something like this may already exist.

Here is an example of how we add the dropdown control to the page, in case you guys even need that.

With CType(.AddControl(New Controls.ComboBox("CodeId", "../../../../CodeId", "Code")), Controls.ComboBox)
                            .ForceSelection = True
                            .ValueField = "LookupID"
                            .DisplayField = "LookupDesc"
                            .Validate.AllowBlank = False
                            .ForceSelection = True
                            .ReadOnly = EditControl.IsFieldReadOnly(10580)
                            .BindData(Model.Codes)
                        End With 

Thanks guys!

-Scott

Since you are using ExtJs you can do something like:

Ext.onReady(function(){

   //place your code here

});

This may solve your problem

You need an onReady event, like what jQuery provides: http://api.jquery.com/ready/. It will run when the page content is ready to be manipulated.