Thursday, 2 October 2025

Automatically Hide Label after some seconds in ASP.Net

Introduction: Hello Guys, “Welcome back” Today, I am here with another one new great article. In this article I explained the implementation about how to automatically hide an ASP.Net Label control after some seconds (say 5 seconds) using JavaScript.

Code of HTML Page

On the HTML page I placed controls a TextBox with the id named txt_name, a Button with the id named btn_submit  and a Label with the id named lbl_message and set visible property of Label  control is set to False. The Label will be made visible from server side after the click of the button.

Enter Name:

<asp:TextBox ID="txt_name" runat="server" />

<br />

<asp:Button ID="btn_submit"  Text="Submit" runat="server" OnClick="Submit" /><br />

<br />

<asp:Label ID="lbl_message" ForeColor="Green" Font-Bold="true" Text="Form has been submitted successfully." runat="server" Visible="false" />

 

Below is the code to make the Label visible on button click.

C#

protected void Submit(object sender, EventArgs e)

{

    Lbl_message.Visible = true;

    ClientScript.RegisterStartupScript(this.GetType(), "alert", "hide_label();", true);

}

 

Automatically Hiding Label control after 02seconds using JavaScript

I created a JavaScript function that will be hiding the Label after 5 seconds when you click on the Buttom. This function using the ClientScript RegisterStartupScript method after clicking the Button.

A variable seconds holds the value which determines after how many seconds the Label will hide. You can set whatever value you need in seconds as per your requirement.

Finally within JavaScript setTimeout function, the Label is hidden by setting its CSS display property to none and the timeout is specified by multiplying the ‘seconds’ variable to 1000 as setTimeout function accepts value in Milliseconds.

<script type="text/javascript">

    function hide_label() {

        var seconds = 2;

        setTimeout(function () {

            document.getElementById("<%=lbl_message.ClientID %>").style.display = "none";

        }, seconds * 1000);

    };

</script>

Conclusion: In above code, I have been explained that how to automatically hide an ASP.Net Label control after some seconds (say 2 seconds) using JavaScript. Bye and take care of yourself Developers. We will come back shortly with the new article.

 

Regards

Programming Hub

 

 

Wednesday, 1 October 2025

Enable Disable Link using JavaScript and jQuery

Introduction: Hello Guys, “Welcome back” Today, I am here with another one new great article. In this article I explained the implementation about how to enable or disable Link (HyperLink) using JavaScript and jQuery. The HTML disabled attribute does not work for HTML Anchor Tags (HyperLink) and they are still clickable.

Join our Channel  on Whtsapp and Telagram for All Updates                                          

Enable Disable Anchor Tags (Links) usingJavaScript

ON the HTML page i placed a HTML Anchor Links (HyperLink) or Anchor tag with the website link and a Button. On the Button is click, the enable_disable_links JavaScript function will be called.

In the function, the values of Button will be checked after click if the value the button will be Disable, then the Anchor Tag or Link will be disabled i.e. non-clickable if the value the button will be Enable, then the Anchor Tag or Link will be disabled i.e. clickable 

Disabling HTML Anchor Links (HyperLink)

In order to disable a HTML Anchor Link (HyperLink), the value of its HREF attribute is copied to the REL attribute and the value of HREF attribute is set to an empty JavaScript function.

This makes the HTML Anchor Link (HyperLink) disabled i.e. non-clickable.

Enabling HTML Anchor Links (HyperLink)

In order to enable a HTML Anchor Link (HyperLink), the value of its REL attribute is copied back to the HREF attribute and the REL attribute is removed.

This makes the HTML Anchor Link (HyperLink) once again enabled i.e. clickable. You can copy and paste this code inside the body tag of the HTML page.

<a href=" https://usingaspdotnet.blogspot.com ">Visit Programming Hub</a><br />

<input type="button" id="btn_Enb_dis " value="Disable" onclick = "enable_disable_links (this)" />

<script type="text/javascript">

    function enable_disable_links(btn) {

        var links = document.getElementsByTagName("a");

        if (btn.value == "Disable") {

            btn.value = "Enable";

            for (var i = 0; i < links.length; i++) {

                var href = links[i].href;

                links[i].setAttribute("rel", href);

                links[i].href = "javascript:;"

            }

        } else {

            btn.value = "Disable";

            for (var i = 0; i < links.length; i++) {

                var href = links[i].getAttribute("rel");

                links[i].removeAttribute("rel");

                links[i].href = href

            }

        }

    }

</script>

Enable Disable Anchor Tags (Links) using jQuery

ON the HTML page i placed a HTML Anchor Links (HyperLink) or Anchor tag with the website link and a Button. On the Button is click, the jQuery Click event handler will be executed.

In Click event handler, the values of Button will be checked after click if the value the button will be Disable, then the Anchor Tag or Link will be disabled i.e. non-clickable if the value the button will be Enable, then the Anchor Tag or Link will be disabled i.e. clickable. 

Disabling HTML Anchor Links (HyperLink)

In order to disable a HTML Anchor Link (HyperLink), the value of its HREF attribute is copied to the REL attribute and the value of HREF attribute is set to an empty JavaScript function.

This makes the HTML Anchor Link (HyperLink) disabled i.e. non-clickable.

Enabling HTML Anchor Links (HyperLink)

In order to enable a HTML Anchor Link (HyperLink), the value of its REL attribute is copied back to the HREF attribute and the REL attribute is removed.

This makes the HTML Anchor Link (HyperLink) once again enabled i.e. clickable. You can copy and paste this code inside the body tag of the HTML page.

<a href=" https://usingaspdotnet.blogspot.com ">Visit Programming Hub</a><br />

<hr />

<input type="button" id="btn_Enb_dis" value="Disable" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script type="text/javascript">

$(function () {

    $("#btn_Enb_dis").click(function () {

        if ($(this).val() == "Disable") {

            $(this).val("Enable");

            $("a").each(function () {

                $(this).attr("rel", $(this).attr("href"));

                $(this).attr("href", "javascript:;");

            });

        } else {

            $(this).val("Disable");

            $("a").each(function () {

                $(this).attr("href", $(this).attr("rel"));

                $(this).removeAttr("rel");

            });

        }

    });

});

</script>

Conclusion: In above code, I have been explained that how to enable or disable Link (HyperLink) using JavaScript and jQuery. Bye and take care of yourself Developers. We will come back shortly with the new article.

Regards

Programming Hub

Tuesday, 30 September 2025

Using Stored Procedures in SQL Server Database

Introduction: Hello Guys, “Welcome back” Today, I am here with another one new great article. In this article I explained How to write stored procedures in SQL Server. This article is compatible for SQL Server edition 2022. It is also compatible to SQL Server  2016, 2017 and 2019 and all below versions or editions.

Join our Channel  on Whtsapp and Telagram for All Updates                                          

It is good to following the practice of using stored procedures can be a good practice for several reasons, including improved performance due to compiled execution plans, reduced network traffic as multiple queries run as one call, enhanced security by restricting direct table access, and better maintainability and reusability of code. However, they also introduce potential complexities, such as greater development effort and the risk of procedures becoming out of sync with the main application codebase.

For the most part yes, SQL injection is far less likely with a stored procedure. Though there are times when you want to pass a stored procedure some data that requires you to use dynamic SQL inside the stored procedure and then you're right back where you started. In this sense I don't see any advantage to them over using parameterized queries in programming languages that support them. Stored Procedures also help in preventing SQL Injections since parameters are used in it. There are many benefits of Store Procedure, First benefit is to it will Create once and call it N number of times. Second benefit of Store procedure will be Reduce traffic since instead of whole query only stored procedure name is sent from front end. And one more benefit of Store procedure is that you can give selected users right to execute a particular stored procedure

Creating a Stored Procedure

Below image will display the syntax for creating a stored procedure. As you can see below to create a stored procedure CREATE keyword is used.



Example

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE get_userdetails

      @userid int = 0

AS

BEGIN

      SET NOCOUNT ON;

      SELECT username,useremail, userdob, useraddress, usercountry

      FROM userdetails WHERE userid=@userid

END

GO

Alter or Modify a Stored Procedure

To modify a stored procedure, use the ALTER PROCEDURE statement in Transact-SQL or your database's equivalent language, or use a graphical tool like SQL Server Management Studio (SSMS). You can change the procedure's body and options using ALTER PROCEDURE, but to change the procedure's name or argument list, you typically must drop it with DROP PROCEDURE and then re-create it using CREATE PROCEDURE.


Example

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER PROCEDURE get_userdetails

      @userid int = 0

AS

BEGIN

      SET NOCOUNT ON;

      SELECT username,useremail, userdob, useraddress, usercountry

      FROM userdetails WHERE userid=@userid

END

GO

 

Drop or Delete a Stored Procedure

To drop or delete a stored procedure, you can use the DROP PROCEDURE command in a SQL query, or use the graphical interface of your database management tool. The general SQL syntax is DROP PROCEDURE procedure_name;, where you replace procedure_name with the actual name of the procedure you want to remove

Example

DROP PROCEDURE get_userdetails

Conclusion: In above code, I have been explained that How to write stored procedures in SQL Server. Bye and take care of yourself Developers. We will come back shortly with the new article.

 

Regards

Programming Hub