Showing posts with label dropdownlist. Show all posts
Showing posts with label dropdownlist. Show all posts

Wednesday, March 28, 2012

Accessing DropDownList in UpdatePanel programmatically

I have an updatepanel within and updatepanel and am trying to access a drop down list as shown below. I am receiving an error saying the object is not set.

Dim LOAN_TYPEAs DropDownList =New DropDownList

LOAN_TYPE = UpdatePanel1.FindControl("UpdatePanel2").FindControl("ddlSIM_TYPE")

If LOAN_TYPE.SelectedValue ="Std"Then 'THIS IS WHERE I RECEIVE MY ERROR

Any ideas?

Try:

Dim LOAN_TYPEAs DropDownList = CType(UpdatePanel1.FindControl("UpdatePanel2").FindControl("ddlSIM_TYPE") , DropDownList)

-Damien


I tried that as well and same message. This is driving me nuts...

Any other ideas? Thanks for your help!


Use UpdatePanel.ContentTemplateContainer.FindControl(), instead.


You are going to hate me but that resulted in the same error message.

UpdatePanel1.ContentTemplateContainer.FindControl("UpdatePanel2").FindControl("ddlSIM_TYPE")


You need to use it on both UpdatePanels. In C#, it would work like this:

UpdatePanel up2 = (UpdatePanel)UpdatePanel1.ContentTemplateContainer.FindControl("UpdatePanel2");
DropDownList ddl = (DropDownList)up2.ContentTemplateContainer.FindControl("ddlSIM_TYPE");

I'm not sure of the exact VB syntax, but hopefully that makes sense.

Though, unless UpdatePanel2 is dynamically generated, you ought to be able to just find the dropdown like this:

DropDownList ddl = (DropDownList)UpdatePanel2.ContentTemplate.FindControl("ddlSIM_TYPE");

Ok, tried that and no luck. Here is the code section:

Dim p2As UpdatePanel = UpdatePanel1.ContentTemplateContainer.FindControl("UpdatePanel2")

Dim PVAs TextBox = p2.ContentTemplateContainer.FindControl("txtSIM_PV")

Dim IAs TextBox = p2.ContentTemplateContainer.FindControl("txtSIM_I")

Dim NAs TextBox = p2.ContentTemplateContainer.FindControl("txtSIM_N")

Dim LOAN_TYPEAs DropDownList = p2.ContentTemplateContainer.FindControl("ddlSIM_TYPE")

If LOAN_TYPE.SelectedValue ="Std"Then

When accessing this if statement i get an object not set error when accessing any of the objects shown above. I have checked and double checked everything and no luck. its inside the Form tag, it has runat=server, etc. Any other ideas - I am at my wits end...

Thanks


Well on the bright side, if you're not getting the error until the conditional, that means the UpdatePanel2 find is working.

Inside UpdatePanel2, are your TextBox and DropDownList controls contained within another control, like a panel or a wizard or a repeater?


Hi,

I agree withgt1329a.

But seeSolution to the FindControl problem for more information about FindControl problem.

Best Regards,

Saturday, March 24, 2012

Accentuation problem

I've an UpdatePanel that has textbox and dropdownlist inside it.
In the textbox I put words with accent, for example: á é í, and the dropdownlist has a AutoPostback = True.
When the SelectedIndex event happens, these controls are reloades but the words that a put with accent shows wrong, ex: ?? ?? ?-

How I correct this?

How about letting the dropdownlist have its own updatepanel?

WS


'Cause all the controls are in the same table, will stay complicated to separate the <td> tags to all the dropdownlist that exists.
But I'll try to do this.


I did your suggestion but the problem happens in the grid now.
I put the words in the text box, select all the dropdownlists and click on a button.
This click save the resulto to a DataGrid, when the resuts go to DataGrid, the words are wrong (accent).

Wednesday, March 21, 2012

A postback via update panel resets TabIndex?

I have a few controls inside an update panel. One of them is a dropdownlist with autopostback = true. After it postbacks (you know in Ajax style, no full page postback) the the tab indexes of the controls seem to get ignored or reset. I end up back at the first control in the tab index or else sometimes no control is focused when hitting the tab key.

Anyone find the same issue?

There's a workaround I found, just in case you're using ASP.NET Ajax.

In my example, I have a FormView and two DropDownLists, the first is called "ddlCountries", with AutoPostBack=True. The second is called "ddlStates".

In my case, my page is using an ScriptManager. And my FormView is inside an UpdatePanel.


Just create an event for the "ddlCountries" as follows:

protected void ddlCountries_SelectedIndexChanged(object sender, EventArgs e){DropDownList ddlStates = (DropDownList)FormView1.FindControl("ddlStates");ScriptManager1.SetFocus(ddlStates);}

And voi-là!!


Thanks I found that solution too, its a pity the tabindex settings are ignored with partial postacks in ASP.net Ajax.

A Blug in ModalPopup

The ModalPopup will be covered by dropdownlist if there is dropdownlist in ContentTemplate

<atlas:UpdatePanel runat=server ID=update1 > <ContentTemplate><asp:DropDownList ID=zoneType runat=server Width="132px" ><asp:ListItem Value=1>other</asp:ListItem></asp:DropDownList>
      ....

This is discussed in a couple of other posts in this forum (please search for details). Briefly, IE creates actual window controls for stuff like this and they aren't subject to the normal layering rules of the page.

a "must select" AutoCompletion control?

Hi,
I want to implement the autocompletion feature to replace my dropdownlist.
(because the list could be long)
I have an ID and a Text in my dropdownlist:
Select OrganizationID, OrganizationName from Organizations
Today the autocompletion allow the user to type anything and also non existing item but provide the exact behavior wanted.
any sample?
thanks.
Jerome.
You need a custom validator on this field I think, look athttp://atlas.asp.net/quickstart/util/srcview.aspx?path=~/atlas/samples/controls/control4.src