Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback

Reply
Thread Tools

Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback

 
 
Luhar Powell via .NET 247
Guest
Posts: n/a
 
      04-01-2005
Hi,

I have simple Itemplate implementation with 2 textboxes and button.
On postback I would like to access values entered by user in the textbox controls.

The Itemplate sample below has two text boxes for first name and last name. There is Ok button that will do process first name and last name entered by the user.

Thanks,
Luhar



<%@ Page %>
<%@ Register TagPrefix="TemplateControlSamples" Namespace="TemplateControlSamples" Assembly="TemplateControlSamples" %>
<script runat=server language=c#>
void Page_Load()
{
DataBind();
}
public void ButtonOK_Click(object sender, System.EventArgs e)
{
Response.Write("Button Ok clicked");
//Call some function with firstname and last name entered by user?
//How do i get access to first name and last name?
}
</script>

<html>

<body>

<form method="POST" runat="server">

Non Templated version:

<TemplateControlSamples:Template1 Message="Hello World!" runat=server/>

<hr>

Templated version:<br>

<TemplateControlSamples:Template1 Message="Hello World!" runat=server>
<MessageTemplate>
<b><i><u>
<%# Container.Message %>
<asp:textbox id=TextBoxFirstName runat="server" NAME="Textbox1"></asp:TextBox><br>
<asp:textbox id=TextBoxLastName runat="server" NAME="Textbox2"></asp:TextBox><br>
<asp:button id=ButtonOK onclick=ButtonOk_Click Text="Ok" Runat="server"></asp:Button>
</u></i></b>
</MessageTemplate>
</TemplateControlSamples:Template1>

</form>

</body>

</html>

/************************************************** *****/
using System;
using System.Web;
using System.Web.UI;

namespace TemplateControlSamples
{

public class TemplateItem : Control, INamingContainer
{
private String _message = null;

public TemplateItem(String message)
{
_message = message;
}

public String Message
{

get
{
return _message;
}
set
{
_message = value;
}
}
}

[
ParseChildren(true)
]
public class Template1 : Control, INamingContainer
{

private ITemplate _messageTemplate = null;
private String _message = null;

public String Message
{

get
{
return _message;
}
set
{
_message = value;
}
}

[
PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(TemplateItem))
]
public ITemplate MessageTemplate
{
get
{
return _messageTemplate;
}
set
{
_messageTemplate = value;
}
}

public override void DataBind()
{
EnsureChildControls();
base.DataBind();
}


protected override void CreateChildControls()
{

// If a template has been specified, use it to create children.
// Otherwise, create a single literalcontrol with message value

if (MessageTemplate != null)
{
Controls.Clear();
TemplateItem i = new TemplateItem(this.Message);
MessageTemplate.InstantiateIn(i);

Controls.Add(i);
}
else
{
this.Controls.Add(new LiteralControl(this.Message));
}
}
}
}



--------------------------------
From: Luhar Powell

--------------------------------
From: Luhar Powell

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>r7ePQV4v90epKLtciIXqKw==</Id>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
repost: custom control client values gone with postback -- no solution found... Pipo ASP .Net 2 12-01-2005 01:04 PM
Re: custom control client values gone with postback Pipo ASP .Net 1 11-26-2005 09:27 PM
custom control client values gone with postback Pipo ASP .Net 3 11-25-2005 05:43 PM
Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback Luhar Powell via .NET 247 ASP .Net Building Controls 0 04-01-2005 04:59 PM
Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback Luhar Powell via .NET 247 ASP .Net Web Controls 0 04-01-2005 04:56 PM



Advertisments