Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 17th, 2007, 02:54 AM
Authorized User
 
Join Date: May 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to DarkForce
Default Change Text of Textbox inside Template

Hi,

I have a Detailsview and a Textbox inside a Templatefield.
I try to access the Textbox in the %%%.cs Data file but i cannot.
Should look like

TextBox1.Text = "Hallo";



So long
__________________
Ivan
 
Old June 17th, 2007, 03:21 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

No, you can't access these controls directly. The DetailsView is a container control that contains these individual controls. Since you can potentially have more than one DetailsView on a page, the DetailsView must ensure that each TextBox and other controls have a unique name.

Depending on when and where you use this code, you can try this:

TextBox myTextBox = (TextBox) DetailsView1.FindControl("TextBox1")
myTextBox.Text = "Hallo";

This code "finds" the TextBox inside the DetailsView and then sets its text.

Hope this helps,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old June 17th, 2007, 12:49 PM
Authorized User
 
Join Date: May 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to DarkForce
Default

Thank you Imar,this helped a lot

So long
 
Old September 14th, 2012, 07:11 AM
Registered User
 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Using JQuery/JavaScript, is it possible to access properties of controls which reside inside EditItemTemplate?
Code:

<!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><link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
    <script src="jquery.js" type="text/javascript"></script>
    <style type ="text/css">
    .clsFind
    {
 
    }
</style>
    <title>

</title></head>
<body>
    <form method="post" action="Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="3Pmn9Z3SnssjpgmTk85Nr2jhTsqd5NHedGdkMUfV+2dPaqpHt7qp/2AWX9qOhiwAFCM9RHQI5rENTpeESwRy0ZZeQVBfClrV5iFUhbf7XplozcfU8eKGVqL1sFReaPgLR/lhLIWzA8NwfBS1ebYMSgbpdja4qj0SwaXKUAsibz3c2KENEyt08DUX5HwAazWpKdOm9jFalKOg+o0ui/NgbDZSHQ9SHJpIyQL7yahDzaJk0Jdd2phbtPcAp48UwabuL6/T2l2uo56gqvTyBoE6S9aF1hDQa7IEAFskaQtw4HqhvPz/66aaN/1Hj6K967JedxNCZCbNIy97gqHLD3C4HznIJBqxcp2gfBfkyA7CwO4=" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<div class="aspNetHidden">

	<input type="hidden" name="__VIEWSTATEENCRYPTED" id="__VIEWSTATEENCRYPTED" value="" />
	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="MEy46W8V6LdjyyEkxaS8Q3uielIKJ8u0QGKH77tD9QAVNTPLEp4rSVZbPSy4z9DPsJn/KADTdCOJVTfLBPoYQghZFTsikn1INk1acz34miDY09vW4qF+EQtlZKF44xIpea0TTMKkXGzADHlQAht/oA337ZeTL6m2WOhnu4CXwgk=" />
</div>
    <div>
        <div>
	<table cellspacing="0" rules="all" border="1" id="DetailsView1" style="height:50px;width:125px;border-collapse:collapse;">
		<tr>
			<td>id</td><td>2</td>
		</tr><tr>
			<td>myRow</td><td>
                        <span id="DetailsView1_Label2">Please type row number:</span>
                        <br />
                        <input name="DetailsView1$txtRowNumber" type="text" id="DetailsView1_txtRowNumber" csCssClass="clsFind" />
                        <input name="DetailsView1$TextBox1" type="text" value="B         " id="DetailsView1_TextBox1" />
                    </td>
		</tr><tr>
			<td colspan="2"><a href="javascript:__doPostBack('DetailsView1$ctl01','')">Update</a>&nbsp;<a href="javascript:__doPostBack('DetailsView1','Cancel$0')">Cancel</a></td>
		</tr><tr>
			<td>Delete</td><td align="left" style="width:20%;">
                            <a id="DetailsView1_lnkDelete" class="clsFind" href="javascript:__doPostBack('DetailsView1$lnkDelete','')">Delete</a>
                            <a id="DetailsView1_lnkShow" class="clsFind" href="javascript:__doPostBack('DetailsView1$lnkShow','')">show</a>
                        </td>
		</tr><tr>
			<td colspan="2"><table>
				<tr>
					<td><span>1</span></td><td><a href="javascript:__doPostBack('DetailsView1','Page$2')">2</a></td>
				</tr>
			</table></td>
		</tr>
	</table>
</div>
        
        <br />
        <input type="submit" name="btnShowControl" value="Show Delete Button" onclick="return ShowControl();" id="btnShowControl" />
 
        <input type="submit" name="btnHideControl" value="Hide Delete Button" onclick="return HideControl();" id="btnHideControl" />

    </div>
    </form>
</body>
</html>
Specifically i am trying to access txtRowNumber.
Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Global parameter calculation inside template Volder XSLT 8 June 20th, 2008 08:10 AM
value-of inside template match RoeZ XSLT 5 April 17th, 2008 12:09 PM
get value of textbox inside datagrid khaink ASP.NET 1.0 and 1.1 Basics 9 October 2nd, 2007 10:05 AM
TextBox inside GridView michurin ASP.NET 2.0 Basics 2 January 13th, 2007 12:51 PM
How to change text in textbox from sub in module jano59 Beginning VB 6 1 September 6th, 2005 12:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.