Click here to Skip to main content
15,569,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, my problem is that i want to display length of the text of textbox in another textbox correspondingly as i type in first textbox. my code as shown below is working properly for a page without masterpage, but i want to do this in a page(ask.aspx) which is attaced to a masterpage(forum.master). my code that is working for a page without mster is
<<pre lang="xml">%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="ADVANCED_FORUM.test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
function showtextlen()
var objcount=document.getElementById("ta2");
var objsub=document.getElementById("ta1");
if(objcount  && objsub)
<body onload="showtextlen();">
    <form id="form1" runat="server">
        <textarea id="ta1" runat="server" onkeyup="showtextlen();" cols="20" rows="2" style="z-index: 101; left: 10px; position: absolute; top: 70px"></textarea>
        <textarea id="ta2" runat="server" cols="20" rows="2" style="z-index: 100; left: 196px; position: absolute; top: 70px"></textarea></div>

this is working properly.
Now my master page code is
<<pre lang="xml">%@ Master Language="C#" AutoEventWireup="true" CodeBehind="forum.master.cs" Inherits="" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
<div id="header" style="height: 273px">
    <div id="logo" style="width: 137px; height: 55px">
        <h1><a href="#">Forums</a></h1>
        <h2><a href="">By Yogesh Sharma</a></h2>
    <div id="menu" style="height: 118px">
            <li class="active"><a href="#" title="">Homepage</a></li>
            <li><a href="#" title="">About Us</a></li>
            <li><a href="main.aspx" title="">View all questions</a></li>
            <li><a href="test.aspx" title="">Unanswered question</a></li>
            <li><a href="ask.aspx" title="">Ask a question</a></li>
     <form id="formm" runat ="server" >
       <asp:ContentPlaceHolder ID ="cp1" runat="server">
           <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 1px; position: absolute;
               top: 167px"></asp:TextBox>

AND my code for a page(ask.aspx) having a masterpage is:
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/forum.Master" CodeBehind="ask.aspx.cs" Inherits="ADVANCED_FORUM.ask" %>
<asp:Content ID="content3" runat="server" ContentPlaceHolderID="cp1">
<asp:Panel ID="Panel1" runat="server" Style="z-index: 104; left: 4px; position: absolute;
        top: 170px" Height="700px" Width="729px" BackColor="#C0C0FF">
        <asp:Button ID="btnpostqst" runat="server" Font-Bold="True" ForeColor="#400040" Height="29px"
            OnClick="btnpostqst_Click" Style="z-index: 100; left: 0px; position: absolute;
            top: 665px" TabIndex="4" Text="Post your question" Width="139px" Font-Italic="True" Font-Underline="True" />
        <asp:TextBox ID="txtquestion" runat="server" BorderColor="#400000" BorderStyle="Ridge"
            Height="503px" Style="z-index: 101; left: 7px; position: absolute; top: 144px"
            TabIndex="3" TextMode="MultiLine" Width="708px" EnableViewState="False" AutoCompleteType="Disabled" >
    <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Italic="True" Font-Underline="True"
        ForeColor="#000040" Style="z-index: 102; left: 2px; position: absolute; top: 33px"
        Text="Subject :">
    <asp:TextBox ID="txtsubject" runat="server" Style="z-index: 103;
        left: 67px; position: absolute; top: 30px" Width="599px" Height="24px" TabIndex="1" OnTextChanged="txtsubject_TextChanged" AutoCompleteType="Disabled">
    <asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Italic="True" Font-Underline="True"
        ForeColor="#000040" Style="z-index: 104; left: 9px; position: absolute; top: 81px"
        Text="Tag :">
    <asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Italic="True" Font-Underline="False"
        ForeColor="#000040" Style="z-index: 105; left: 12px; position: absolute; top: 120px"
    <asp:TextBox ID="txtcount" runat="server" Height="23px" Style="z-index: 106; left: 685px;
        position: absolute; top: 31px" Width="31px" Enabled="False">
    <asp:DropDownList ID="ddtag" runat="server" Style="z-index: 107; left: 70px; position: absolute;
        top: 79px" Width="354px" EnableViewState="False" TabIndex="2" Height="32px">

here i want to know that where is should define my javascript function and where to use this function please tell in details with example.. its a big problem for me..

1 solution

Here's a simple example: Count Textarea Characters With Javascript[^].

There's lots of resources available for this (just Google!), or if you have trouble with implementation, go ahead and post another question with more specifics.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900