Dec 22, 2010

create and Add Dyanmically image,label controll in asp.net

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
//public SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MSKEMSSqlConnectionString"].ConnectionString);

protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = GetData("Select * from sample");

//create control
System.Web.UI.WebControls.Image img1; //Image
Label lbl1;//label for blank spaces

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
lbl1 = new Label();
lbl1.Text = " ";
img1 = new System.Web.UI.WebControls.Image();
img1.ImageUrl = ds.Tables[0].Rows[i].ItemArray[1].ToString().Trim();// give the img path
img1.Height = Unit.Pixel(169);
img1.Width = Unit.Pixel(202);
img1.BorderStyle = BorderStyle.Solid;
img1.BorderWidth = Unit.Pixel(3);
img1.BorderColor = System.Drawing.Color.White;
//add control to place holder
PlaceHolder1.Controls.Add(img1);
PlaceHolder1.Controls.Add(lbl1);
}
}

public DataSet GetData(String strSql)
{
DataSet ds = new DataSet();

SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=tempdb;Persist Security Info=True;User ID=sa;Password=sa;");
SqlDataAdapter da = new SqlDataAdapter(strSql, con);

if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
da.Fill(ds);
con.Close();
return ds;
}



}

Create and add controls dyna,ically in Asp.net

Visit it.........


http://www.c-sharpcorner.com/UploadFile/sd_patel/DynamicallyCreateASPNETControls11232005020626AM/DynamicallyCreateASPNETControls.aspx

Dec 12, 2010

Connection String for Lan Connceted server .... Try this

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Use serverName\instanceName as Data Source to connect to a specific SQL Server instance.
Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername\SQLEXPRESS where you substitute Servername with the name of the computer where the SQL Server 2005 Express installation resides.



===========================================================================
or May be try this Link
http://connectionstrings.com/Forum/mysql/connecting-to-mysql-from-another-pc-on-the-network

How to set Current possition of html controls in master page

// Code for Content place holder

HtmlControl home = (HtmlControl)this.Page.Master.FindControl("mainMenu").FindControl("faqs");
        home.Attributes.Add("class", "current");


//code for master html

<div id="templatemo_menu">
   
            <ul id="mainMenu" runat="server">
                 <li><a id ="Default" runat="server"  href="Default.aspx" >Home</a></li>
                <li><a id ="feedback" runat="server"  href="support.aspx?fdk=fdk">Feedback</a></li>
                <li><a id ="faqs" runat="server" href="faqs.aspx">Faqs</a></li>
                <li><a id ="support" runat="server" href="support.aspx?fdk=sup">Support</a></li>

                <li><a id ="MyAccount" runat="server" href="MyAccount.aspx">My Account</a></li>
                <li><a id ="contactus" runat="server" href="contactus.aspx">Contact Us</a></li>
              
            </ul>       
   
        </div> <!-- end of templatemo_menu -->

Dec 4, 2010

How to check the Data List / List view Selected items In Java Script

            string id = "";
            string id1 = "";
            for (int i = 0; i < dlBuddy.Items.Count; i++)
            {
                HtmlInputCheckBox chk = (HtmlInputCheckBox)dlBuddy.Items[i].FindControl("CheckBox1");
                if (chk.Checked == true)
                {
                    string chkid = chk.Value;
                    id = id + "," + chkid;
                }

            }

AJAY HELP: Get DropDownList Values in Java Script

AJAY HELP: Get DropDownList Values in Java Script: " function SendDpd() { var myval = document.getElementById('DropDownList1').options[0].text; alert('Value =' +..."

Dec 2, 2010

Get DropDownList Values in Java Script

  function SendDpd()
{
        var myval = document.getElementById('DropDownList1').options[0].text;

           
        alert("Value =" + myval);
        window.open('Default6.aspx');
        //salert("Hi");
  }

Dec 1, 2010

Launching a Modal Popup Window from Server Code

Launching a Modal Popup Window from Server Code

Christian Wenz

Overview

The ModalPopup control in the AJAX Control Toolkit offers a simple way to create a modal popup using client-side means. However some scenarios require that the opening of the modal popup is triggered on the server-side.

Steps

First of all, an ASP.NET Button web control is required to demonstrate how the ModalPopup control works. Add such a button within the <form> element on a new page:


<asp:Button ID="ClientButton" runat="server" Text="Launch Modal Popup (Client)" />


Then, you need the markup for the popup you want to create. Define it as an <asp:Panel> control and make sure that it includes a Button control. The ModalPopup control offers the functionality to make such a button close the popup; otherwise there is no easy way to let it vanish.


<asp:Panel ID="ModalPanel" runat="server" Width="500px">
 ASP.NET AJAX is a free framework for quickly creating a new generation of more 
 efficient, more interactive and highly-personalized Web experiences that work 
 across all the most popular browsers.<br />
 <asp:Button ID="OKButton" runat="server" Text="Close" />
</asp:Panel>


Next add the ModalPopup control from the ASP.NET AJAX Toolkit to the page. Set properties for the button which loads the control, the button which makes it disappear, and the ID of the actual popup.


<ajaxToolkit:ModalPopupExtender ID="mpe" runat="server" TargetControlId="ClientButton" 
 PopupControlID="ModalPanel" OkControlID="OKButton" />


As with all web pages based on ASP.NET AJAX; the Script Manager is required to load the necessary JavaScript libraries for the different target browsers:


<asp:ScriptManager ID="asm" runat="server" />


Run the example in the browser. When you click on the button, the modal popup appears. In order to achieve the same effect using server-side code, a new button is required:


<asp:Button ID="ServerButton" runat="server" Text="Launch Modal Popup (Server)" 
 OnClick="ServerButton_Click" />


As you can see, a click on the button generates a postback and executes the ServerButton_Click()launchModal() is executed to be exact, the JavaScript function will be executed once the page has been loaded: method on the server. In this method, a JavaScript function called


<script runat="server">
 protected void ServerButton_Click(object sender, EventArgs e)
 {
 ClientScript.RegisterStartupScript(this.GetType(), "key", "launchModal();", true);
 }
</script>


The job of launchModal() is to display the ModalPopup. The launchModal() function is executed once the complete HTML page has been loaded. At that moment, however, the ASP.NET AJAX framework has not been fully loaded yet. Therefore, the launchModal() function just sets a variable that the ModalPopup control must be shown later on:


<script type="text/javascript">
 var launch = false;
 function launchModal() 
 {
 launch = true;
 }


The pageLoad() JavaScript function is a special function that gets executed once ASP.NET AJAX has been fully loaded. Therefore we add code to this function to show the ModalPopup control, but only if launchModal() has been called before:


function pageLoad() 
 {
 if (launch) 
 {
 $find("mpe").show();
 }
 }
</script>


The $find() function is looking for a named element on the page and expects the server-side ID as a parameter. Therefore, $find("mpe") returns the client representation of the ModalPopup control; its show() method lets the popup appear.
The modal popup appears when either of the buttons is clicked

Check Email Id

if(email.trim()=="")
                {
                 alert("Kindly enter valid Email Address");
                document.getElementById("<%=textemail.ClientID %>").focus();
                return false;
                }
           
         var emailPat =/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
    // var emailPat = /^([\w\d\-\.]+)@{1}(([\w\d\-]{1,67})|([\w\d\-]+\.[\w\d\-]{1,67}))\.(([a-zA-Z\d]{2,3})(\.[a-zA-Z\d]{2})?)$/;
     var emailid=document.getElementById("<%=textemail.ClientID %>").value;
     var matchArray = emailid.match(emailPat);
     if (matchArray == null)
    {
               alert("Please enter valid Email Address.");
               document.getElementById("<%=textemail.ClientID %>").focus();
               return false;
    }

Disable Back button Of browser

<script language="JavaScript">
javascript:window.history.forward(1);
</script>

Nov 30, 2010

Ascii Values of all

ASCII Table and Description

ASCII stands for American Standard Code for Information Interchange. Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as 'a' or '@' or an action of some sort. ASCII was developed a long time ago and now the non-printing characters are rarely used for their original purpose. Below is the ASCII character table and this includes descriptions of the first 32 non-printing characters. ASCII was actually designed for use with teletypes and so the descriptions are somewhat obscure. If someone says they want your CV however in ASCII format, all this means is they want 'plain' text with no formatting such as tabs, bold or underscoring - the raw format that any computer can understand. This is usually so they can easily import the file into their own applications without issues. Notepad.exe creates ASCII text, or in MS Word you can save a file as 'text only'

Ascii Table

Extended ASCII Codes



EBCDIC and IBM Scan Codes


Key KeyCode Ascii Value
A 65 65
B 66 66
C 67 67
D 68 68
E 69 69
F 70 70
G 71 71
H 72 72
I 73 73
J 74 74
K 75 75
L 76 76
M 77 77
N 78 78
O 79 79
P 80 80
Q 81 81
R 82 82
S 83 83
T 84 84
U 85 85
V 86 86
W 87 87
X 88 88
Y 89 89
Z 90 90
0 48 48
1 49 49
2 50 50
3 51 51
4 52 52
5 53 53
6 54 54
7 55 55
8 56 56
9 57 57
a 65 97
b 66 98
c 67 99
d 68 100
e 69 101
f 70 102
g 71 103
h 72 104
i 73 105
j 74 106
k 75 107
l 76 108
m 77 109
n 78 110
o 79 111
p 80 112
q 81 113
r 82 114
s 83 115
t 84 116
u 85 117
v 86 118
w 87 119
x 88 120
y 89 121
z 90 122
Numpad 0 96 48
Numpad 1 97 49
Numpad 2 98 50
Numpad 3 99 51
Numpad 4 100 52
Numpad 5 101 53
Numpad 6 102 54
Numpad 7 103 55
Numpad 8 104 56
Numpad 9 105 57
Multiply 106 42
Add 107 43
Enter 13 13
Subtract109 45
Decimal 110 46
Divide 111 47
F1 112 0
F2 113 0
F3 114 0
F4 115 0
F5 116 0
F6 117 0
F7 118 0
F8 119 0
F9 120 0
F10 This key is reserved by the system and cannot be used in ActionScript. F11 122 0
F12 123 0
F13 124 0
F14 125 0
F15 126 0
Backspace8 8
Tab 9 9
Enter 13 13
Shift 16 0
Control 17 0
Caps Lock20 0
Esc 27 27
Spacebar32 32
Page Up 33 0
Page Down34 0
End 35 0
Home 36 0
Left Arrow37 0

java Sript

Calling JavaScript from ASP.NET Master Page and Content Pages - Part II
 
In this article, we will see some common problems and their solutions of calling JavaScript from a Master/Content page. This article is Part II of the series ‘Calling JavaScript from ASP.NET Master Page and Content Pages’ and in this article; we will cover JavaScript in Content Pages. Part I of this article can be read over here Calling JavaScript from ASP.NET Master Page and Content Pages - Part I
Call JavaScript from Content Page
Here are some common scenarios of executing JavaScript from a Content Page.
1. Create a JavaScript function on the fly and call the JavaScript function in the Content Page Page_Load() event
C#
    protected void Page_Load(object sender, EventArgs e)
    {       
        const string someScript = "alertMe";
        if (!ClientScript.IsStartupScriptRegistered(this.GetType(), someScript))
        {
            ClientScript.RegisterStartupScript(this.GetType(),
                someScript, "alert('I was called from Content page!')", true);
        }
    }
VB.NET
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim someScript As String = "alertMe"
        If (Not ClientScript.IsStartupScriptRegistered(Me.GetType(), someScript)) Then
            ClientScript.RegisterStartupScript(Me.GetType(), someScript, "alert('I was called from Content page!')", True)
        End If
    End Sub
2. Call a JavaScript function declared in a .js file from the Content Page
If you have a .js file and want to call the function from your Content Page, then here’s how to do so.
Let’s create a .js file called TestScript.js and add the following function in the .js file.
function insideJS() {
    alert('Inside .js');
}
Assuming that your .js file is kept in a Script folder, reference the file in your MasterPage in the following manner.
<head runat="server">
    <title></title>
    <script src="Scripts/TestScript.js" type="text/javascript"></script>
...
Now in your Content Page(in our case Default.aspx.cs or .vb), call the JavaScript function on the Page_Load:
C#
 
    protected void Page_Load(object sender, EventArgs e)
    {       
        if (!Master.Page.ClientScript.IsStartupScriptRegistered("alert"))
        {
            Master.Page.ClientScript.RegisterStartupScript
                (this.GetType(), "alert", "insideJS();", true);
        }
    }
 
VB.NET
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If (Not Master.Page.ClientScript.IsStartupScriptRegistered("alert")) Then
                  Master.Page.ClientScript.RegisterStartupScript (Me.GetType(), "alert", "insideJS();", True)
            End If
      End Sub
3. Referencing the .js file from a Content Page instead of the Master page
The approach shown above in Tip 2 works well, however this approach would add a reference to the .js file for every page in the application (since we are adding the .js in the Master Page). If you want to avoid this approach, then remove the reference added to the .js file in Tip 2 in the Master Page. Now add a reference to the .js file from the Content Page using the ‘RegisterClientScriptInclude’ as shown below:
C#
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterClientScriptInclude("selective", ResolveUrl(@"Scripts\TestScript.js"));
        if (!Master.Page.ClientScript.IsStartupScriptRegistered("alert"))
        {
            Master.Page.ClientScript.RegisterStartupScript
                (this.GetType(), "alert", "insideJS();", true);
        }
    }
VB.NET
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Page.ClientScript.RegisterClientScriptInclude("selective", ResolveUrl("Scripts\TestScript.js"))
        If (Not Master.Page.ClientScript.IsStartupScriptRegistered("alert")) Then
            Master.Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "insideJS();", True)
        End If
    End Sub
Using this approach, we can avoid referencing the .js file for every content page.
Note: This approach adds the JavaScript reference inside the <body>tag of the page.
4. Declare JavaScript inside the Content page and execute it
If you are looking out to declare JavaScript inside the Content Page, then here’s how to do so. Add the following markup inside the Content page (in our case Default.aspx)
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Panel ID="panelContent" GroupingText="ContentPage Controls" runat="server">
        <asp:TextBox ID="txtContent" runat="server"></asp:TextBox>
        <asp:Button ID="btnContent" runat="server" Text="Button" OnClientClick="Populate();" />
    </asp:Panel>
    <script type="text/javascript" language="javascript">
        function Populate() {
            {
                document.getElementById('<%=txtContent.ClientID%>').value = "Hi";               
            }
        }
    </script>
</asp:Content>
The markup shown above populates the textbox with some text on a button click.
5. Accessing a Control on the Master Page From a ContentPage using JavaScript
In our previous article, we saw how in Tip 5 To access a control on the ContentPage From a Master Page using JavaScript. In this tip, we will see how to access a control kept on the MasterPage from a ContentPage. Do the following:
We have added a textbox control to the <body> of the MasterPage  as shown below:
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="panelMaster" GroupingText="MasterPage controls" runat="server">      
            <asp:TextBox ID="txtMaster" runat="server"></asp:TextBox>
            <br />
        </asp:Panel>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
       
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
We will now access this TextBox ‘txtMaster’ in the ContentPage using JavaScript
To do so, go to the Content page (Default.aspx) and add the following line below the <Page> directive to register the MasterPage
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
...
<%@ MasterType VirtualPath="~/MasterPage.master" %>
...
Now in the code behind of Default.aspx.cs or .vb, access the MasterPage control in the following manner
C#
   protected void Page_Load(object sender, EventArgs e)
    {
        TextBox tb = (TextBox)Master.FindControl("txtMaster");
        string val = tb.ClientID;
        string script = @"<script>
        function PopulateMaster() {
            document.getElementById('" + val + @"').value = 'Via Content Page. Love dotnetcurry';               
        }
        PopulateMaster();
        </script>";
        if (!Page.ClientScript.IsStartupScriptRegistered("Mast"))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(),
                "Mast", script);
        }
 
    }
VB.NET
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim tb As TextBox = CType(Master.FindControl("txtMaster"), TextBox)
            Dim val As String = tb.ClientID
            Dim script As String = "<script>" & ControlChars.CrLf & "        function PopulateMaster() {" & ControlChars.CrLf & "            document.getElementById('" & val & "').value = 'Via Content Page. Love dotnetcurry.com';                " & ControlChars.CrLf & "        }" & ControlChars.CrLf & "        PopulateMaster();" & ControlChars.CrLf & "        </script>"
            If (Not Page.ClientScript.IsStartupScriptRegistered("Mast")) Then
                  Page.ClientScript.RegisterStartupScript(Me.GetType(), "Mast", script)
            End If
 
   End Sub
Observe how we have used the RegisterStartupScript instead of RegisterClientScriptBlock. The main difference is that the 'RegisterStartupScript' method places the JavaScript at the bottom of the ASP.NET page right before the closing </form> element whereas the 'RegisterClientScriptBlock' method places the JavaScript directly after the opening <form> element in the page. Had we used the 'RegisterClientScriptBlock', the browser would have executed the JavaScript before the text box is on the page. Therefore, the JavaScript would not have been able to find a ‘txtMaster’ and would give a control not found error. Understanding this simple difference between the two methods can save you hours of work!
6. Call JavaScript function from an ASP.NET AJAX enabled Content Page
If your content page is wrapped in an ASP.NET AJAX UpdatePanel, then you cannot use the ClientScript.RegisterStartupScript to call a JavaScript function during a partial-page postback. Instead, use the ScriptManager.RegisterStartupScript() method.
C#
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(@"<script language='javascript'>");
        sb.Append(@"alert('I love dotnetcurry.com');");       
        sb.Append(@"</script>");
 
        ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax", sb.ToString(), false);
 
    }
VB.NET
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim sb As New System.Text.StringBuilder()
        sb.Append("<script language='javascript'>")
        sb.Append("alert('I love dotnetcurry');")
        sb.Append("</script>")
 
        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ajax", sb.ToString(), False)
 
    End Sub
Observe that the last parameter for RegisterStartupScript() is set to 'false'. This means that the <script> tags will not be added automatically. Since we have already inserted the <script> tags while creating the script in the StringBuilder, we do not need to insert them now.

java Sript

Calling JavaScript from ASP.NET Master Page and Content Pages - Part II
 
In this article, we will see some common problems and their solutions of calling JavaScript from a Master/Content page. This article is Part II of the series ‘Calling JavaScript from ASP.NET Master Page and Content Pages’ and in this article; we will cover JavaScript in Content Pages. Part I of this article can be read over here Calling JavaScript from ASP.NET Master Page and Content Pages - Part I
Call JavaScript from Content Page
Here are some common scenarios of executing JavaScript from a Content Page.
1. Create a JavaScript function on the fly and call the JavaScript function in the Content Page Page_Load() event
C#
    protected void Page_Load(object sender, EventArgs e)
    {       
        const string someScript = "alertMe";
        if (!ClientScript.IsStartupScriptRegistered(this.GetType(), someScript))
        {
            ClientScript.RegisterStartupScript(this.GetType(),
                someScript, "alert('I was called from Content page!')", true);
        }
    }
VB.NET
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim someScript As String = "alertMe"
        If (Not ClientScript.IsStartupScriptRegistered(Me.GetType(), someScript)) Then
            ClientScript.RegisterStartupScript(Me.GetType(), someScript, "alert('I was called from Content page!')", True)
        End If
    End Sub
2. Call a JavaScript function declared in a .js file from the Content Page
If you have a .js file and want to call the function from your Content Page, then here’s how to do so.
Let’s create a .js file called TestScript.js and add the following function in the .js file.
function insideJS() {
    alert('Inside .js');
}
Assuming that your .js file is kept in a Script folder, reference the file in your MasterPage in the following manner.
<head runat="server">
    <title></title>
    <script src="Scripts/TestScript.js" type="text/javascript"></script>
...
Now in your Content Page(in our case Default.aspx.cs or .vb), call the JavaScript function on the Page_Load:
C#
 
    protected void Page_Load(object sender, EventArgs e)
    {       
        if (!Master.Page.ClientScript.IsStartupScriptRegistered("alert"))
        {
            Master.Page.ClientScript.RegisterStartupScript
                (this.GetType(), "alert", "insideJS();", true);
        }
    }
 
VB.NET
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If (Not Master.Page.ClientScript.IsStartupScriptRegistered("alert")) Then
                  Master.Page.ClientScript.RegisterStartupScript (Me.GetType(), "alert", "insideJS();", True)
            End If
      End Sub
3. Referencing the .js file from a Content Page instead of the Master page
The approach shown above in Tip 2 works well, however this approach would add a reference to the .js file for every page in the application (since we are adding the .js in the Master Page). If you want to avoid this approach, then remove the reference added to the .js file in Tip 2 in the Master Page. Now add a reference to the .js file from the Content Page using the ‘RegisterClientScriptInclude’ as shown below:
C#
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterClientScriptInclude("selective", ResolveUrl(@"Scripts\TestScript.js"));
        if (!Master.Page.ClientScript.IsStartupScriptRegistered("alert"))
        {
            Master.Page.ClientScript.RegisterStartupScript
                (this.GetType(), "alert", "insideJS();", true);
        }
    }
VB.NET
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Page.ClientScript.RegisterClientScriptInclude("selective", ResolveUrl("Scripts\TestScript.js"))
        If (Not Master.Page.ClientScript.IsStartupScriptRegistered("alert")) Then
            Master.Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "insideJS();", True)
        End If
    End Sub
Using this approach, we can avoid referencing the .js file for every content page.
Note: This approach adds the JavaScript reference inside the <body>tag of the page.
4. Declare JavaScript inside the Content page and execute it
If you are looking out to declare JavaScript inside the Content Page, then here’s how to do so. Add the following markup inside the Content page (in our case Default.aspx)
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Panel ID="panelContent" GroupingText="ContentPage Controls" runat="server">
        <asp:TextBox ID="txtContent" runat="server"></asp:TextBox>
        <asp:Button ID="btnContent" runat="server" Text="Button" OnClientClick="Populate();" />
    </asp:Panel>
    <script type="text/javascript" language="javascript">
        function Populate() {
            {
                document.getElementById('<%=txtContent.ClientID%>').value = "Hi";               
            }
        }
    </script>
</asp:Content>
The markup shown above populates the textbox with some text on a button click.
5. Accessing a Control on the Master Page From a ContentPage using JavaScript
In our previous article, we saw how in Tip 5 To access a control on the ContentPage From a Master Page using JavaScript. In this tip, we will see how to access a control kept on the MasterPage from a ContentPage. Do the following:
We have added a textbox control to the <body> of the MasterPage  as shown below:
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="panelMaster" GroupingText="MasterPage controls" runat="server">      
            <asp:TextBox ID="txtMaster" runat="server"></asp:TextBox>
            <br />
        </asp:Panel>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
       
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
We will now access this TextBox ‘txtMaster’ in the ContentPage using JavaScript
To do so, go to the Content page (Default.aspx) and add the following line below the <Page> directive to register the MasterPage
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
...
<%@ MasterType VirtualPath="~/MasterPage.master" %>
...
Now in the code behind of Default.aspx.cs or .vb, access the MasterPage control in the following manner
C#
   protected void Page_Load(object sender, EventArgs e)
    {
        TextBox tb = (TextBox)Master.FindControl("txtMaster");
        string val = tb.ClientID;
        string script = @"<script>
        function PopulateMaster() {
            document.getElementById('" + val + @"').value = 'Via Content Page. Love dotnetcurry';               
        }
        PopulateMaster();
        </script>";
        if (!Page.ClientScript.IsStartupScriptRegistered("Mast"))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(),
                "Mast", script);
        }
 
    }
VB.NET
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim tb As TextBox = CType(Master.FindControl("txtMaster"), TextBox)
            Dim val As String = tb.ClientID
            Dim script As String = "<script>" & ControlChars.CrLf & "        function PopulateMaster() {" & ControlChars.CrLf & "            document.getElementById('" & val & "').value = 'Via Content Page. Love dotnetcurry.com';                " & ControlChars.CrLf & "        }" & ControlChars.CrLf & "        PopulateMaster();" & ControlChars.CrLf & "        </script>"
            If (Not Page.ClientScript.IsStartupScriptRegistered("Mast")) Then
                  Page.ClientScript.RegisterStartupScript(Me.GetType(), "Mast", script)
            End If
 
   End Sub
Observe how we have used the RegisterStartupScript instead of RegisterClientScriptBlock. The main difference is that the 'RegisterStartupScript' method places the JavaScript at the bottom of the ASP.NET page right before the closing </form> element whereas the 'RegisterClientScriptBlock' method places the JavaScript directly after the opening <form> element in the page. Had we used the 'RegisterClientScriptBlock', the browser would have executed the JavaScript before the text box is on the page. Therefore, the JavaScript would not have been able to find a ‘txtMaster’ and would give a control not found error. Understanding this simple difference between the two methods can save you hours of work!
6. Call JavaScript function from an ASP.NET AJAX enabled Content Page
If your content page is wrapped in an ASP.NET AJAX UpdatePanel, then you cannot use the ClientScript.RegisterStartupScript to call a JavaScript function during a partial-page postback. Instead, use the ScriptManager.RegisterStartupScript() method.
C#
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(@"<script language='javascript'>");
        sb.Append(@"alert('I love dotnetcurry.com');");       
        sb.Append(@"</script>");
 
        ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax", sb.ToString(), false);
 
    }
VB.NET
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim sb As New System.Text.StringBuilder()
        sb.Append("<script language='javascript'>")
        sb.Append("alert('I love dotnetcurry');")
        sb.Append("</script>")
 
        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ajax", sb.ToString(), False)
 
    End Sub
Observe that the last parameter for RegisterStartupScript() is set to 'false'. This means that the <script> tags will not be added automatically. Since we have already inserted the <script> tags while creating the script in the StringBuilder, we do not need to insert them now.

What is the use of n-tier architecture and 3-tier architecture?

how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it ...