Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Wednesday, 19 September 2012

JS : Disable Whole RadioButtonList by Javascript, No PostBack

Hello, Readers! 
http://forums.asp.net/t/1844055.aspx
Recently, I replied to an answer.
most of times we try no to postback (using updatepanel is another thing, we dont want to respond to the server for better performance.)
We can disable 1 radio button or item easily but how would be disable all RadioButtons or Checkboxes? which are dynamic, by SQLDatasource ETC.
I made this Jquery.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        function toggleStatus() {
        var Drp = document.getElementById('DropDownList1');
        if (Drp.value == "Disable RadioList") {
                $('#some :input').attr('disabled', true);
            } else {
                $('#some :input').removeAttr('disabled');
            }
        } </script>

HTML Markup
<asp:DropDownList ID="DropDownList1" runat="server" onchange="toggleStatus()">
            <asp:ListItem>Enable RadioList</asp:ListItem>
            <asp:ListItem>Disable RadioList</asp:ListItem>
        </asp:DropDownList>
    
        <br /><div id="some">
        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem>Good?</asp:ListItem>
            <asp:ListItem>Bad?</asp:ListItem>
            <asp:ListItem>No idea!</asp:ListItem>
        </asp:RadioButtonList></div>
It will disable All Radio Buttons of the Div "some"
Thanks for Reading..

Wednesday, 8 August 2012

JS : Reload Parent Page After Child Popup Close.

I've Answered this Question many Times

This is your Simple Popup Page on any Button click event.


string popup = "";
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "PopupScript", popup, false);

And This is your Popup.aspx and Close Button Event
protected void CloseButton_Click(object sender, EventArgs e)
 {
        
   CloseButton.Attributes.Add("onclick", "return windowclose();");
   ClientScript.RegisterStartupScript(GetType(), "CloseScript", "window.opener.location.reload(); window.close();", true);
  }

Good Luck`

JS : Fire Popup on Page_Load or any Click Event.

We can Call javascript from our Page.aspx as well as from our Codebehind of  Page.aspx.cs
Method #1:
you can simple write this Code:
 string popup = "<script language='javascript'>" + "window.open('YOUR-POPUP-PAGE.aspx','CustomPopUp', " + "'fullscreen=no,height=240,width=648,top=250,left=250,location=0,directories=0,status=no,scrollbars=no, dependant = no, alwaysRaised = yes, menubar=no,resizable=no')" + "</script>";
 ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "PopupScript", popup, false);
Method #2:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!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">
    <script>
        function popup() {
            window.open("Default.aspx");
        }
    </script>
</head>
<body onload="popup();">
    <form id="form1" runat="server">
    </form>
</body>
</html>


Good Luck`

Monday, 6 August 2012

Custom Title of Alert of JS?

People love to know that is there a way to put our custom Alert on Javascript Alert("Message");
No, Its Impossible but there are Some JQuery we can achieve this Goal..

jQuery Alert Dialogs (Alert, Confirm, & Prompt Replacements)

Screenshot

DEMO :


I Hope this will Help you!
Good Luck`

JS : Minimum & Maximum Validation from ASP TextBox

Some times we avoid ASP.Net Validations controls So, JavaScript is preferable for avoiding Post-backs.
I made this JS.


Now, on your SubmitButton click Event you can add
In your Page_Load Event..
Button1.Attribute.Add("onclick", "validate()");
//OR
// simply you can add on your HTML Mark of Button1
OnClientClick="validate()"
Good Luck`

Saturday, 4 August 2012

ASP.NET Read Value using Javascript from Disabled Textbox.

If the asp:TextBox is Disabled so its a little tricky to read from Javascript.
There is actually no way to read the value from a disabled or hidden textbox from server side. But sometimes we need to prevent users from entering values to a textbox after some condition but access the already provided textbox value from the server side. For that, we can set the readonly property of the textbox to true. Setting it to true will not prevent server side from accessing it. It will just prevent end users from entering value to the textbox.


As for example, you can set it to readonly mode with following javascript code snippet.
document.getElementById(textboxID).readOnly = true;


Now you can access that textbox from server side even though it prevent end users from entering values.


Good Luck`

ASP.NET Disable TextBox using Javascript.

I've Briefly Answered:  http://forums.asp.net/post/5038180.aspx
Task : the goal was to disable asp:Textbox on asp:Radiobutton Check/uncheck. ( without PostBack we know with Codebehind its easy..)


So,

Javascript Code write under <head> Section
    <script type="text/javascript">
       function Radio() {
        var No = document.getElementById('<%= NoRadioButton.ClientID %>').checked;
        var Yes = document.getElementById('<%= YesRadioButton.ClientID %>').checked;
        if (No == true)
            {
                document.getElementById('<%= YourTextBoxID.ClientID %>').disabled = true;
            }
         if (Yes == true)
            {
                document.getElementById('<%= YourTextBoxID.ClientID %>').disabled = false;
            }
        }
        
    </script>
and your Page aspx. HTML Markup of Radio Button!
        <asp:RadioButton ID="YesRadioButton" runat="server" GroupName="Same" Text="Yes" onClick="Radio()" />
        <asp:RadioButton ID="NoRadioButton" runat="server" GroupName="Same" Text="No" onClick="Radio()" />
Good luck`

WaterMark on ASP.NET TextBox Using Javascript

Going to explain.. How can we use watermark on ASP.NET TextBox using Javascript ( Yes, I know we can use AJAX ControlToolkit for WaterMark),


I've answered in the forums:
http://forums.asp.net/p/1830453/5094893.aspx

It's CSS Code:

<style type="text/css">
        .WaterMarkedTextBox
        {
            height: 16px;
            width: 168px;
            padding: 2px 2 2 2px;
            border: 1px solid #BEBEBE;
            background-color: #F0F8FF;
            color: gray;
            font-size: 8pt;
            text-align: center;
        }
        .WaterMarkedTextBoxPSW
        {
            background-position: center;
            height: 16px;
            width: 168px;
            padding: 2px 2 2 2px;
            border: 1px solid #BEBEBE;
            background-color: #F0F8FF;
            color: white;
            vertical-align: middle;
            text-align: right;
            background-image: url(Images/psw_wMark.png);
            background-repeat: no-repeat;
        }
        .NormalTextBox
        {
            height: 16px;
            width: 168px;
        }
    </style>

It's your Javascript Code:

<script language="javascript" type="text/javascript">
        function Focus(objname, waterMarkText) {
            obj = document.getElementById(objname);
            if (obj.value == waterMarkText) {
                obj.value = "";
                obj.className = "NormalTextBox";
                if (obj.value == "User ID" || obj.value == "" || obj.value == null) {
                    obj.style.color = "black";
                }
            }
        }
        function Blur(objname, waterMarkText) {
            obj = document.getElementById(objname);
            if (obj.value == "") {
                obj.value = waterMarkText;
                if (objname != "txtPwd") {
                    obj.className = "WaterMarkedTextBox";
                }
                else {
                    obj.className = "WaterMarkedTextBoxPSW";
                }
            }
            else {
                obj.className = "NormalTextBox";
            }

            if (obj.value == "User ID" || obj.value == "" || obj.value == null) {
                obj.style.color = "gray";
            }
        }
    </script> 

It's HTML Markup of your Page.aspx (EXAMPLE)

<body>
    <form id="form1" runat="server">
    <div>
        <h3>
            Watermark Textbox using JavaScript and CSS</h3>
    </div>
    <table>
        <tr>
            <td>
                User Id
            </td>
            <td>
                <asp:TextBox ID="txtUserId" runat="server" 
                onfocus="Focus(this.id,'User ID')"
                    onblur="Blur(this.id,'User ID')" 
                    Width="126px" CssClass="WaterMarkedTextBox">User ID</asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Password
            </td>
            <td>
                <asp:TextBox ID="txtPwd" TextMode="Password" 
                runat="server" onfocus="Focus(this.id,'')"
                    onblur="Blur(this.id,'')" Width="126px" 
                        CssClass="WaterMarkedTextBoxPSW" />
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <asp:Button ID="Button1" runat="server" Text="Submit" />
            </td>
        </tr>
    </table>
    </form>
</body> 


Good Luck` Hope So, it was easy then using AJAX..

Twitter Delicious Facebook Digg Stumbleupon Favorites More