Change the property "DefaultValue" of the "ControlParameter" control with javascript

I already have an idea on how to do this, but I realized that the control “ControlParameter” did not have an “Id” property (which is needed for the JS). Is there a different way to use JavaScript to change the “DefaultValue” property without the need of using the “Id” property?

Here is the JavaScript and code that I have been working with:


        function ChangePropertyValue(propertyName, newpropertyValue) {
        var ControlParameter = document.getElementById(propertyName)
        ControlParameter.DefaultValue = newpropertyValue

        <asp:Button ID="btntest" runat="server" Text="try" OnClick="ChangePropertyValue(??, 17)"/>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>" 
        SelectCommand="SELECT [Id], [ContentTitle], [Content] FROM [Table1] WHERE ([Id] = @Id)">
            <asp:ControlParameter ControlID="ListView1" DefaultValue="16" Name="Id" 
                PropertyName="SelectedValue" Type="Int32"/>

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

You can’t access a ControlParameter client side. ControlParameters are used to bind the value of a Control property server side, they are not rendered to the client. You can, however, set the Default value of the ControlParameter programmatically in your Code Behind.

SqlDataSource1.SelectParameters["id"].DefaultValue = "value";

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply