Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6353517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:25:37+00:00 2026-05-24T22:25:37+00:00

I Have an aspx page that contains 2 buttons Update and Default. I have

  • 0

I Have an aspx page that contains 2 buttons “Update” and “Default”. I have a dropdown list which contains a few values, say 1 to 10. When I click on Default button, the dropdown is set to a default value, say 4. If I wish to set the dropdown value to 3, I choose 3 and click on Update button and the changes are saved somewhere, maybe a DB.

Initially, Update button is disabled. Only if any changes are made to the dropdown, the Update button is enabled. Assuming that the Update button is initially disabled, I click the Default button to set the dropdown to its initial value. When I do that, a postback happens during which the Update button suddenly becomes enabled and then disabled. How do I avoid this? During page refresh, I don’t want the disabled Update button to become enabled and then disabled. ALl this happens in a millisecond but its still visible.

is there any way out of this?

Design code is as follows:
ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LogSettings.aspx.cs" Inherits="Settings_LogSettings" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Diagnostic Server Configuration Tool</title>
    <link rel="stylesheet" type="text/css" href="../css/style001.css" />
    <style type="text/css">
        a.info
        {
            position: relative; /*this is the key*/
            z-index: 24; /*background-color:#ccc;*/
            color: #000;
            border-width: 0px;
            border-style: none;
            text-decoration: none;
        }

        a.info:hover
        {
            z-index: 25;
            background-color: #ff0;
        }

        a.info span
        {
            display: none;
        }

        a.info:hover span
        {
            /*the span will display just on :hover state*/
            display: block;
            position: absolute;
            bottom: 2em;
            right: 2em;
            width: 15em;
            border: 1px solid #0cf;
            background-color: #cff;
            color: #000;
            text-align: left;
            padding: 5px;
        }
    </style>
    <script language="javascript" type="text/javascript">
        function setDefaults() {
            if (document.getElementById("dlLoggingLevel").value != document.getElementById("dlLoggingLevel_Def").value) {
                document.getElementById("dlLoggingLevel").value = document.getElementById("dlLoggingLevel_Def").value;
                document.getElementById("imgLoggingLevel").src = "../images/field_ok.png";
                document.getElementById("imgLoggingLevelUndo").style.display = "inline";
                document.getElementById("btnUpdate").disabled = false;
            }
            if (document.getElementById("txtMaxFileSize").value != document.getElementById("txtMaxFileSize_Def").value) {
                document.getElementById("txtMaxFileSize").value = document.getElementById("txtMaxFileSize_Def").value;
                document.getElementById("imgMaxSize").src = "../images/field_ok.png";
                document.getElementById("imgMaxSizeUndo").style.display = "inline";
                document.getElementById("btnUpdate").disabled = false;
            }
        }
        function isNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;

            return true;
        }
    </script>
    <script language="javascript" type="text/javascript" src="../Css/wcf_validate.js"></script>
</head>
<body>
    <form id="form1" runat="server">

    <div>
        <br />
        <div class="divEditHeader" id="EditHeader">
            <h1>
                Logging Configuration
            </h1>
            <table width="100%">
                <tr>
                    <td align="left">
                        <asp:Button CssClass="formEditBtn" runat="server" ID="btnUpdate" Text="Update" OnClick="btnUpdate_Click"
                            Enabled="false" />
                        <button class="formEditBtn" onclick="javascript:setDefaults();" causesvalidation="false">
                            Default</button>
                    </td>
                    <td align="right">
                    </td>
                </tr>
            </table>
        </div>
        <br />
        <table class="InputTable">
            <tr class="Prompt">
                <td class="Prompt">
                    Logging Level
                </td>
                <td>
                    <asp:DropDownList runat="server" ID="dlLoggingLevel">
                        <asp:ListItem Text="NONE" Value="none"></asp:ListItem>
                        <asp:ListItem Text="FATAL" Value="fatal"></asp:ListItem>
                        <asp:ListItem Text="ERROR" Value="error"></asp:ListItem>
                        <asp:ListItem Text="WARNING" Value="warning"></asp:ListItem>
                        <asp:ListItem Text="INFO" Value="info"></asp:ListItem>
                        <asp:ListItem Text="DEBUGLOW" Value="debuglow"></asp:ListItem>
                        <asp:ListItem Text="DEBUGMEDIUM" Value="debugmedium"></asp:ListItem>
                        <asp:ListItem Text="DEBUGHIGH" Value="debughigh"></asp:ListItem>
                        <asp:ListItem Text="DEBUGALL" Value="debugall"></asp:ListItem>
                    </asp:DropDownList>
                    <img id="imgLoggingLevel" src="../images/blank.png" />
                    <asp:TextBox runat="server" ID="dlLoggingLevel_Init" Style="display: none"></asp:TextBox>
                    <asp:TextBox runat="server" ID="dlLoggingLevel_Def" Style="display: none"></asp:TextBox>
                    <img id="imgLoggingLevelUndo" src="../images/restore.png" style="display: none; cursor: hand"
                        onmouseover="this.src='../Images/restore_hov.png'" onmouseout="this.src='../Images/restore.png'"
                        onclick="restoreValue('dlLoggingLevel','dlLoggingLevel_Init','imgLoggingLevel','imgLoggingLevelUndo')" />
                </td>
                <td>
                    <a href="javascript: void 0" class="info">
                        <img src="../images/help.png" border="0">
                        <span><font size="2">Enter the desired level of diagnostic data logging. Default: INFO.
                        </font></span></a>
                </td>
            </tr>
            <tr class="Prompt">
                <td class="Prompt">
                    Maximum Log File Size(MB)
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtMaxFileSize" Width="36px" MaxLength="3"></asp:TextBox>
                    <asp:TextBox runat="server" ID="txtMaxFileSize_Init" Style="display: none"></asp:TextBox>
                    <asp:TextBox runat="server" ID="txtMaxFileSize_Def" Style="display: none"></asp:TextBox>
                    <img id="imgMaxSize" src="../images/blank.png" />
                    <asp:CustomValidator runat="server" ID="valMaxSize" ControlToValidate="txtMaxFileSize"
                        Display="Dynamic" ErrorMessage="" ClientValidationFunction="MaxSize_Validate"></asp:CustomValidator>
                    <img id="imgMaxSizeUndo" src="../images/restore.png" style="display: none; cursor: hand"
                        onmouseover="this.src='../images/restore_hov.png'" onmouseout="this.src='../images/restore.png'"
                        onclick="restoreValue('txtMaxFileSize','txtMaxFileSize_Init','imgMaxSize','imgMaxSizeUndo')" />
                </td>
                <td>
                    <a href="javascript: void 0" class="info">
                        <img src="../images/help.png" border="0">
                        <span><font size="2">Enter the maximum log file size in MB. Default: 2 MB. Range: 1
                            - 100 MB. </font></span></a>
                </td>
            </tr>
        </table>
        <br />
        <asp:Label runat="server" ID="lblMessage" Font-Bold="true"></asp:Label>
        <br />
    </div>
    </form>
</body>
</html>

Code-Behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DiagnosticCommon;
using System.Drawing;

public partial class Settings_LogSettings : System.Web.UI.Page
{
    const string EnvVariable = "DIAGNOSTICSERVER";
    const string ConfigFileName = "DiagnosticService.exe.config";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Security.EnforceSecurity())
            Response.Redirect("Login.aspx");

        if (!IsPostBack)
        {
            DebugHelper.MaxDebugLevel = DebugHelper.Parse(ConfigReader.GetValue("LoggingLevel"));
            DebugHelper.MaxLogFileSize = long.Parse(ConfigReader.GetValue("LogFileSize"));

            txtMaxFileSize.Attributes.Add("onchange", "javascript:MaxSize_Validate('',this);");
            txtMaxFileSize.Attributes.Add("onkeypress", "return isNumberKey(event)");

            dlLoggingLevel.Attributes.Add("onchange", "javascript:Logging_Validate('',this);");

            BindData();
            BindInitData();
            BindDefaults();
        }

    }

    private void BindData()
    {
        string installPath = Environment.GetEnvironmentVariable(EnvVariable);
        try
        {
            dlLoggingLevel.SelectedValue = ConfigReader.GetValue("LoggingLevel");
            txtMaxFileSize.Text = ConfigReader.GetValue("LogFileSize");
        }
        catch (Exception ex)
        {
            lblMessage.Text += ex.Message + "<br>" + installPath;
            lblMessage.ForeColor = Color.Red;
        }

    }

    private void BindInitData()
    {
        string installPath = Environment.GetEnvironmentVariable(EnvVariable);
        try
        {
            dlLoggingLevel_Init.Text = ConfigReader.GetValue("LoggingLevel");
            txtMaxFileSize_Init.Text = ConfigReader.GetValue("LogFileSize");
        }
        catch (Exception ex)
        {
            lblMessage.Text += ex.Message + "<br>" + installPath;
            lblMessage.ForeColor = Color.Red;
        }

    }

    protected void btnCancel_Click(object sender, EventArgs e)
    { 
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    { 
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            lblMessage.Text = "";
            ConfigReader.SetValue("LoggingLevel", dlLoggingLevel.SelectedValue);
            ConfigReader.SetValue("LogFileSize", txtMaxFileSize.Text);

            lblMessage.Text = "Configuration updated.";
            lblMessage.ForeColor = Color.Green;
            btnUpdate.Enabled = false;
            BindInitData();

        }
        catch (Exception ex)
        {
            lblMessage.Text += ex.Message;
            lblMessage.ForeColor = Color.Red;
        }
    }

    private void BindDefaults()
    {
        try
        {
            dlLoggingLevel_Def.Text = ConfigReader.GetDefault("LoggingLevel");
            txtMaxFileSize_Def.Text = ConfigReader.GetDefault("LogFileSize");
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex.Message;
            lblMessage.ForeColor = Color.Red;
            btnUpdate.Enabled = false;
        }

    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:25:37+00:00Added an answer on May 24, 2026 at 10:25 pm

    Since the button has no type defined, the default type is used which is a submit button.
    This means that when you click the Default button, the JS code is running but then the form is submitted.

    To avoid the submission simply make the button be ordinary button:

    <button type="button" class="formEditBtn" onclick="javascript:setDefaults();" causesvalidation="false">Default</button>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an .aspx page that contains two buttons one is btnCancel and another
I have a ASPX Page that contains several user controls, which are loaded dynamically
I have an aspx page that contains a checkbox, and a button. The button
I would like to have an aspx page that contains something like.... <form id=form1
I have an aspx page that has a @Page directive which points to a
I have a simple user control that contains some buttons that fire events which
I have an aspx page that contains a user control. The user control has
I have an asp page (Default.aspx) that displays the diff between two text files.
I have an aspx page that contains a number of collapsiblepanels and I want
I have a page which contains a textbox and a button, let's say its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.