Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I need to set the insert parameter to a SelectedValue of a Dropdown list that is an int. This should be easy but I cannot get it to work in my main application. It works in my test application. But my test app does not have multiple layers of UpdatePanels, tabs, etc. I have done every suggestion I could find and it still does not work. The error is that it can't find Control x for the ControlParameter. This is my markup:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<ig:WebTab ID="WebTab1" runat="server" Height="700px" Width="900px" 
 <Tabs>
<ig:ContentTabItem runat="server" Text="Offices">
        <Template>
            <asp:UpdatePanel ID="UpdatePanel6" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <table id="tblInsert" style="width: 875px; background-color:#F0F8FF; text-align:left;">
                    <tr>
                        <td colspan="4" align="left" class="style1">
                            <b>Add New Office:</b>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Address Prefix:
                        </td>
                        <td>
                            <asp:TextBox ID="txtAddressPrefix" runat="server" Text="" ClientIDMode="Static"/>
                        </td>
                        <td>
                            Address:
                        </td>
                        <td>
                            <asp:TextBox ID="txtAddress" runat="server" Text="" ClientIDMode="Static" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Address Suffix:
                        </td>
                        <td>
                            <asp:TextBox ID="txtAddressSuffix" runat="server" Text="" ClientIDMode="Static" />
                        </td>
                        <td>
                            City:
                        </td>
                        <td>
                            <asp:TextBox ID="txtCity" runat="server" Text="" ClientIDMode="Static" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            City Mailing:
                        </td>
                        <td>
                            <asp:TextBox ID="txtCityMailing" runat="server" Text="" ClientIDMode="Static" />
                        </td>
                        <td>
                            State:
                        </td>
                        <td>
                            <asp:TextBox ID="txtState" runat="server" Text="" ClientIDMode="Static" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Zip:
                        </td>
                        <td>
                            <asp:TextBox ID="txtZip" runat="server" Text="" ClientIDMode="Static" />
                        </td>
                        <td>
                            County ID:
                        </td>
                        <td>
                            <asp:DropDownList ID="ddlCounty" runat="server"
                                DataSourceID="SqlDataSource9" 
                                DataValueField="ID"
                                DataTextField="Name" ClientIDMode="Static">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Lat:
                        </td>
                        <td>
                            <asp:TextBox ID="txtLat" runat="server" Text="" ClientIDMode="Static" />
                            <asp:MaskedEditExtender ID="MaskedEditExtender3" runat="server" MaskType="Number"
                                TargetControlID="txtLat" Mask="99.999999999" AcceptNegative="Left">
                            </asp:MaskedEditExtender>
                        </td>
                        <td>
                            Long:
                        </td>
                        <td>
                            <asp:TextBox ID="txtLong" runat="server" Text="" ClientIDMode="Static" />
                            <asp:MaskedEditExtender ID="MaskedEditExtender4" runat="server" MaskType="Number"
                                TargetControlID="txtLong" Mask="99.999999999" AcceptNegative="Left">
                            </asp:MaskedEditExtender>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4" align="left">  
                             <asp:Button ID="btnAddOffice" runat="server" OnClick="btnAddOffice_Click" Text="Add" />     
                        </td>
                    </tr>
                </table>
                </ContentTemplate>
            </asp:UpdatePanel>
        </Template>
    </ig:ContentTabItem>
 </Tabs>
</ig:WebTab>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ don't want to show this :) %>" 
    InsertCommand="phyadmInsOffices" InsertCommandType="StoredProcedure">
        <InsertParameters>
            <asp:ControlParameter Name="AddressPrefix" ControlID="txtAddressPrefix" PropertyName="Text" Type="String" DefaultValue="" ConvertEmptyStringToNull="false" />
            <asp:ControlParameter Name="Address" ControlID="txtAddress" PropertyName="Text" Type="String" DefaultValue="" ConvertEmptyStringToNull="false"  />      
            <asp:ControlParameter Name="AddressSuffix" ControlID="txtAddressSuffix" PropertyName="Text" Type="String" DefaultValue="" ConvertEmptyStringToNull="false"  />
            <asp:ControlParameter Name="City" ControlID="txtCity" PropertyName="Text" Type="String" DefaultValue="" ConvertEmptyStringToNull="false"  />
            <asp:ControlParameter Name="CityMailing" ControlID="txtCityMailing" PropertyName="Text" Type="String" DefaultValue="" ConvertEmptyStringToNull="false"  />
            <asp:ControlParameter Name="State" ControlID="txtState" PropertyName="Text" Type="String" DefaultValue="" ConvertEmptyStringToNull="false" />
            <asp:ControlParameter Name="Zip" ControlID="txtZip" PropertyName="Text" Type="String" DefaultValue="" ConvertEmptyStringToNull="false"  />
            <asp:ControlParameter Name="CountyID" ControlID="ddlCounty" PropertyName="SelectedValue" Type="Int32"/>
            <asp:ControlParameter Name="Lat" ControlID="txtLat" PropertyName="Text" Type="Decimal" DefaultValue="" ConvertEmptyStringToNull="true" />
            <asp:ControlParameter Name="Long" ControlID="txtLong" PropertyName="Text" Type="Decimal" DefaultValue="" ConvertEmptyStringToNull="true" />    
        </InsertParameters>
</asp:SqlDataSource>        
</asp:Content>

This is the code behind:

protected void btnAddOffice_Click(object sender, EventArgs e)
{
    SqlDataSource1.Insert();

    txtAddressPrefix.Text = "";
    txtAddress.Text = "";
    txtAddressSuffix.Text = "";
    txtCity.Text = "";
    txtCityMailing.Text = "";
    txtState.Text = "";
    txtZip.Text = "";
    txtLat.Text = "";
    txtLong.Text = "";
    ddlCounty.SelectedIndex = 0;
}

I apologize for the length but it is the layers that is giving me the problem. I set all of the controls with ClientIDMode="Static" so that I could refer to the controls with only the Id name. But the error is" Can't find control 'x' for ControlParameter 'x'.

I tried using the complete name but that does not work either...same error.

I tried changing all of the paremeters from ControlParameter to Parameter but the I need the SelectedValue of the Dropdown.

Can you set the values of the Insert Parameter in the code behind? The documentation says you can set a DefaultValue but how do you assign the actual value to the parameter?

Thanks.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.