473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

IPostBackDataHandler.LoadPostData

I've been building some custom controls which have some special functionality
with the data I use from a web service, specifically the ability to data bind
to attributes (without an accessor method).

However I've come accross an interesting issue with using them. I have
reimplemented the class from
public class WCCombobox : Control, IPostBackDataHandler
so that I can load the post data back in. It works great, it gets to the
method and loads it in from the post back namevaluecollection. however when
the same control is put on a usercontrol, which is put on the page, rather
than put directly on the page, the loadPostData event doesnt actually get
called.

It works fine directly on the page. It doesnt work on the user control. I've
put 2 controls on the same page, one in a usercontrol, the other directly on
the page, and as I said, the one in the usercontrol doesnt work. The one
directly on the page does.

Has anybody come accross this before? Does anybody have any sugestions on
what I might not be doing to fix this?
Nov 19 '05 #1
9 2353
When you are writing out the postable tag, what id and name attribute are
you writing out? Pretend you are writing out a text box.

writer.AddAttribute( "type", "text" );
writer.AddAttribute( "name", UniqueID );
writer.AddAttribute( "id", ClientID );
writer.RenderBeginTag( HtmlTextWriterTag.Input );
writer.RenderEndTag();

Notice the UniqueID and ClientID, there is no ID anywhere.

UserControl implements INamingContainer which will ensure all controls have
unique IDs.

Image if you had on your page a asp:TextBox id="txtName" and in your
UserControl (id="myUC" ) you had another textbox called "txtName". There
would be all sorts of naming collisions. The textbox in your usercontrol
will render out the name and ID "myUC_txtName", or something to that affect.

If this doesn't help you out, post some of your overridden Render code and I
can help you through it.

bill


"brian.mills" <br********@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
I've been building some custom controls which have some special functionality with the data I use from a web service, specifically the ability to data bind to attributes (without an accessor method).

However I've come accross an interesting issue with using them. I have
reimplemented the class from
public class WCCombobox : Control, IPostBackDataHandler
so that I can load the post data back in. It works great, it gets to the
method and loads it in from the post back namevaluecollection. however when the same control is put on a usercontrol, which is put on the page, rather
than put directly on the page, the loadPostData event doesnt actually get
called.

It works fine directly on the page. It doesnt work on the user control. I've put 2 controls on the same page, one in a usercontrol, the other directly on the page, and as I said, the one in the usercontrol doesnt work. The one
directly on the page does.

Has anybody come accross this before? Does anybody have any sugestions on
what I might not be doing to fix this?

Nov 19 '05 #2
Hmmm. Thats not exactly how I'm rendering the control. Are there any good
articles you know of to render the control? I'm actually rendering a string,
a specific string because I want precise control over the HTML. (I've added
attributes onto the <input tag which get used by client side java script).

I'll try that out now though and see if it helps, I definatly am not using
the unique ID, or the client ID. I'll have to have a look at them.

Brian.

"William F. Robertson, Jr." wrote:
When you are writing out the postable tag, what id and name attribute are
you writing out? Pretend you are writing out a text box.

writer.AddAttribute( "type", "text" );
writer.AddAttribute( "name", UniqueID );
writer.AddAttribute( "id", ClientID );
writer.RenderBeginTag( HtmlTextWriterTag.Input );
writer.RenderEndTag();

Notice the UniqueID and ClientID, there is no ID anywhere.

UserControl implements INamingContainer which will ensure all controls have
unique IDs.

Image if you had on your page a asp:TextBox id="txtName" and in your
UserControl (id="myUC" ) you had another textbox called "txtName". There
would be all sorts of naming collisions. The textbox in your usercontrol
will render out the name and ID "myUC_txtName", or something to that affect.

If this doesn't help you out, post some of your overridden Render code and I
can help you through it.

bill


"brian.mills" <br********@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
I've been building some custom controls which have some special

functionality
with the data I use from a web service, specifically the ability to data

bind
to attributes (without an accessor method).

However I've come accross an interesting issue with using them. I have
reimplemented the class from
public class WCCombobox : Control, IPostBackDataHandler
so that I can load the post data back in. It works great, it gets to the
method and loads it in from the post back namevaluecollection. however

when
the same control is put on a usercontrol, which is put on the page, rather
than put directly on the page, the loadPostData event doesnt actually get
called.

It works fine directly on the page. It doesnt work on the user control.

I've
put 2 controls on the same page, one in a usercontrol, the other directly

on
the page, and as I said, the one in the usercontrol doesnt work. The one
directly on the page does.

Has anybody come accross this before? Does anybody have any sugestions on
what I might not be doing to fix this?


Nov 19 '05 #3
There really is nothing wrong with rendering the control using strings, you
are doing this in the override Render method of the control? Would you mind
posting some of your render code? The code of the html element you are
posting back. You still can have precise control over rendering using the
HtmlTextWriter classes.

As far as articles, I would recommend this book for writing server controls:

http://www.microsoft.com/mspress/books/5728.asp

The html element that you are wanting to process the postback data on should
use name= UniqueID. UniqueID will be the same as ID unless you place your
control in a UserControl, or a repeater, or any other control that
implements INamingContainer.

I could go further into why it works, and doesn't work just rendering the
ID, but most people aren't THAT interested in it. <grin>

bill
"brian.mills" <br********@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
Hmmm. Thats not exactly how I'm rendering the control. Are there any good
articles you know of to render the control? I'm actually rendering a string, a specific string because I want precise control over the HTML. (I've added attributes onto the <input tag which get used by client side java script).

I'll try that out now though and see if it helps, I definatly am not using
the unique ID, or the client ID. I'll have to have a look at them.

Brian.

"William F. Robertson, Jr." wrote:
When you are writing out the postable tag, what id and name attribute are you writing out? Pretend you are writing out a text box.

writer.AddAttribute( "type", "text" );
writer.AddAttribute( "name", UniqueID );
writer.AddAttribute( "id", ClientID );
writer.RenderBeginTag( HtmlTextWriterTag.Input );
writer.RenderEndTag();

Notice the UniqueID and ClientID, there is no ID anywhere.

UserControl implements INamingContainer which will ensure all controls have unique IDs.

Image if you had on your page a asp:TextBox id="txtName" and in your
UserControl (id="myUC" ) you had another textbox called "txtName". There would be all sorts of naming collisions. The textbox in your usercontrol will render out the name and ID "myUC_txtName", or something to that affect.
If this doesn't help you out, post some of your overridden Render code and I can help you through it.

bill


"brian.mills" <br********@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
I've been building some custom controls which have some special

functionality
with the data I use from a web service, specifically the ability to data
bind
to attributes (without an accessor method).

However I've come accross an interesting issue with using them. I have
reimplemented the class from
public class WCCombobox : Control, IPostBackDataHandler
so that I can load the post data back in. It works great, it gets to
the method and loads it in from the post back namevaluecollection. however

when
the same control is put on a usercontrol, which is put on the page, rather than put directly on the page, the loadPostData event doesnt actually get called.

It works fine directly on the page. It doesnt work on the user control. I've
put 2 controls on the same page, one in a usercontrol, the other
directly on
the page, and as I said, the one in the usercontrol doesnt work. The

one directly on the page does.

Has anybody come accross this before? Does anybody have any sugestions on what I might not be doing to fix this?


Nov 19 '05 #4
There really is nothing wrong with rendering the control using strings, you
are doing this in the override Render method of the control? Would you mind
posting some of your render code? The code of the html element you are
posting back. You still can have precise control over rendering using the
HtmlTextWriter classes.

As far as articles, I would recommend this book for writing server controls:

http://www.microsoft.com/mspress/books/5728.asp

The html element that you are wanting to process the postback data on should
use name= UniqueID. UniqueID will be the same as ID unless you place your
control in a UserControl, or a repeater, or any other control that
implements INamingContainer.

I could go further into why it works, and doesn't work just rendering the
ID, but most people aren't THAT interested in it. <grin>

bill
"brian.mills" <br********@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
Hmmm. Thats not exactly how I'm rendering the control. Are there any good
articles you know of to render the control? I'm actually rendering a string, a specific string because I want precise control over the HTML. (I've added attributes onto the <input tag which get used by client side java script).

I'll try that out now though and see if it helps, I definatly am not using
the unique ID, or the client ID. I'll have to have a look at them.

Brian.

"William F. Robertson, Jr." wrote:
When you are writing out the postable tag, what id and name attribute are you writing out? Pretend you are writing out a text box.

writer.AddAttribute( "type", "text" );
writer.AddAttribute( "name", UniqueID );
writer.AddAttribute( "id", ClientID );
writer.RenderBeginTag( HtmlTextWriterTag.Input );
writer.RenderEndTag();

Notice the UniqueID and ClientID, there is no ID anywhere.

UserControl implements INamingContainer which will ensure all controls have unique IDs.

Image if you had on your page a asp:TextBox id="txtName" and in your
UserControl (id="myUC" ) you had another textbox called "txtName". There would be all sorts of naming collisions. The textbox in your usercontrol will render out the name and ID "myUC_txtName", or something to that affect.
If this doesn't help you out, post some of your overridden Render code and I can help you through it.

bill


"brian.mills" <br********@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
I've been building some custom controls which have some special

functionality
with the data I use from a web service, specifically the ability to data
bind
to attributes (without an accessor method).

However I've come accross an interesting issue with using them. I have
reimplemented the class from
public class WCCombobox : Control, IPostBackDataHandler
so that I can load the post data back in. It works great, it gets to
the method and loads it in from the post back namevaluecollection. however

when
the same control is put on a usercontrol, which is put on the page, rather than put directly on the page, the loadPostData event doesnt actually get called.

It works fine directly on the page. It doesnt work on the user control. I've
put 2 controls on the same page, one in a usercontrol, the other
directly on
the page, and as I said, the one in the usercontrol doesnt work. The

one directly on the page does.

Has anybody come accross this before? Does anybody have any sugestions on what I might not be doing to fix this?


Nov 19 '05 #5
Below is the render method I have at the moment.

I spent some time re coding a text box control to inherit from WebControl,
instead of just control. Now it apears to work, but I dont think my
postBackDataHandler is the one that is kicking in, as it never stops in the
break point for the control that I wrote for the control on the user control.
It does stop for the one on the page it self still. Do i actually have to
call the post back data handler method for the usercontrols, and then for the
controls on the user control.

[DefaultProperty("Text"),
ToolboxData("<{0}:WCTextbox runat=server></{0}:WCTextbox>")]
public class WCTextbox : System.Web.UI.WebControls.WebControl,
IPostBackDataHandler
{
protected override void Render(HtmlTextWriter output)
{
string lStr = "";
// If outputing printable form just write out the value
if ( this.printableForm) {
output.Write( "<span id=\"" + this.UniqueID + "\" class=\"" +
this.CssClass + "\">" + this.Value + "</span>");
}
// Creating an actual text box
else if ( this.lines > 1 ) {
// Add main values to string
lStr = "<textarea name=\"" + this.ClientID + "\" id=\"" + this.UniqueID
+ "\" cols=\"" + (this.sizePx * 0.12).ToString()
+ "\" style=\"width:" + this.sizePx.ToString() + "px;" + this.Style
+ "\" rows=\"" + this.lines
+ "\" class=\"" + this.CssClass
+ "\"";
// Add validation attibutes if required
if ( this.validationUse ) {
lStr = lStr + " validation=\"" + this.validationString + "\"
displayname=\"" + this.displayName + "\" onfocus=\"javascript:MakeWhite(
this);\"";
}
lStr = lStr + ">" + this.Value + "</textarea>";
// Write out complete code to page
output.Write( lStr);
} else {
// Add main values to string
lStr = "<input type=\"text\" name=\"" + this.ClientID + "\" id=\"" +
this.UniqueID
+ "\" value=\"" + this.Value
+ "\" size=\"" + (this.sizePx * 0.12).ToString()
+ "\" style=\"width:" + this.sizePx.ToString() + "px;" + this.getStyles()
+ "\" class=\"" + this.CssClass
+ "\"";
// Add max length if required
if ( this.maxLength > 0 ) {
lStr = lStr + " maxlength=\"" + this.maxLength.ToString() + "\"";
}
// Add validation attibutes if required
if ( this.validationUse ) {
lStr = lStr + " validation=\"" + this.validationString + "\"
displayname=\"" + this.displayName + "\" onfocus=\"javascript:MakeWhite(
this);\"";
}
lStr = lStr + ">";
// Write out complete code to page
output.Write( lStr);
}
}
}
Nov 19 '05 #6
Below is the render method I have at the moment.

I spent some time re coding a text box control to inherit from WebControl,
instead of just control. Now it apears to work, but I dont think my
postBackDataHandler is the one that is kicking in, as it never stops in the
break point for the control that I wrote for the control on the user control.
It does stop for the one on the page it self still. Do i actually have to
call the post back data handler method for the usercontrols, and then for the
controls on the user control.

[DefaultProperty("Text"),
ToolboxData("<{0}:WCTextbox runat=server></{0}:WCTextbox>")]
public class WCTextbox : System.Web.UI.WebControls.WebControl,
IPostBackDataHandler
{
protected override void Render(HtmlTextWriter output)
{
string lStr = "";
// If outputing printable form just write out the value
if ( this.printableForm) {
output.Write( "<span id=\"" + this.UniqueID + "\" class=\"" +
this.CssClass + "\">" + this.Value + "</span>");
}
// Creating an actual text box
else if ( this.lines > 1 ) {
// Add main values to string
lStr = "<textarea name=\"" + this.ClientID + "\" id=\"" + this.UniqueID
+ "\" cols=\"" + (this.sizePx * 0.12).ToString()
+ "\" style=\"width:" + this.sizePx.ToString() + "px;" + this.Style
+ "\" rows=\"" + this.lines
+ "\" class=\"" + this.CssClass
+ "\"";
// Add validation attibutes if required
if ( this.validationUse ) {
lStr = lStr + " validation=\"" + this.validationString + "\"
displayname=\"" + this.displayName + "\" onfocus=\"javascript:MakeWhite(
this);\"";
}
lStr = lStr + ">" + this.Value + "</textarea>";
// Write out complete code to page
output.Write( lStr);
} else {
// Add main values to string
lStr = "<input type=\"text\" name=\"" + this.ClientID + "\" id=\"" +
this.UniqueID
+ "\" value=\"" + this.Value
+ "\" size=\"" + (this.sizePx * 0.12).ToString()
+ "\" style=\"width:" + this.sizePx.ToString() + "px;" + this.getStyles()
+ "\" class=\"" + this.CssClass
+ "\"";
// Add max length if required
if ( this.maxLength > 0 ) {
lStr = lStr + " maxlength=\"" + this.maxLength.ToString() + "\"";
}
// Add validation attibutes if required
if ( this.validationUse ) {
lStr = lStr + " validation=\"" + this.validationString + "\"
displayname=\"" + this.displayName + "\" onfocus=\"javascript:MakeWhite(
this);\"";
}
lStr = lStr + ">";
// Write out complete code to page
output.Write( lStr);
}
}
}
Nov 19 '05 #7
No it still doesnt call it for the control on the user controls.

It does however If I use a normal ASP textbox control.

Do I have to call the load post back data from the page, call it for each
usercontrol, and then call it for each control on the user control? Or how
does it get subscribed to?
Nov 19 '05 #8
No it still doesnt call it for the control on the user controls.

It does however If I use a normal ASP textbox control.

Do I have to call the load post back data from the page, call it for each
usercontrol, and then call it for each control on the user control? Or how
does it get subscribed to?
Nov 19 '05 #9
The UniqueID needs to be rendered out for the name property. The name
property is what the key for what is posted back.

You should either use StringBuilder and its Append method for building your
string, or should just write directly to the writer.

(your code)
// Add main values to string
lStr = "<textarea name=\"" + this.UniqueID+ "\" id=\"" + this.ClientID
+ "\" cols=\"" + (this.sizePx * 0.12).ToString()
+ "\" style=\"width:" + this.sizePx.ToString() + "px;" + this.Style
+ "\" rows=\"" + this.lines
+ "\" class=\"" + this.CssClass
+ "\"";
// Add validation attibutes if required
if ( this.validationUse )
{
lStr = lStr + " validation=\"" + this.validationString + "\"
displayname=\"" + this.displayName + "\" onfocus=\"javascript:MakeWhite(
this);\"";
}
lStr = lStr + ">" + this.Value + "</textarea>";
// Write out complete code to page
output.Write( lStr);
(end your code)

This section code code actually loads and creates about 46 different
strings. Not too efficient.

Here is a sample of the writer approach.
output.Write( "<textarea name=\"" );
output.Write( this.UniqueID );
output.Write( "\" id=\" );
output.Write( this.ClientID );
....

Here is the HtmlTextWriter way to render this code. this covers the whole
section listed above. This is the method I prefer from my developers as it
is easier to read, and you don't have to count "\""\" \" + "\"" stuff. Did
you ever miss one and have to figure out exactly where to add a missing \"?

When you call RenderBeginTag, the HtmlTextWriter will step through all the
attributes that have been added and will write them out. After the opening
tag is send to the browser, you add the inner html and then on to the EndTag
that will renderd the closing tag. The HtmlTextWriter is smart enough to
remember what tag you are currently one. (I believe it uses a stack to keep
the tags order with).

output.AddAttribute( "name", this.UniqueID );
output.AddAttribute( "id", this.ClientID );
output.AddAttribute( "cols", (this.sizePx * 0.12).ToString() );
output.AddAttribute( "style", "width:" + this.sizePx + "px" + this.Style );
output.AddAttribute( "rows", this.lines.ToString() );
output.AddAttribute( "class", this.CssClass );

if ( this.validationUse )
{
output.AddAttribute( "validation", this.validationString );
output.AddAttribute( "displayName", this.displayName );
output.AddAttribute( "onfocus", "javascript:MakeWhite( this);" );
}

output.RenderBeginTag( HtmlTextWriterTag.Textarea );
output.Write( this.Value ); //you probably should encode this
//output.Write( System.Web.HttpUtility.HtmlEncode( this.Value );
output.RenderEndTag();

HTH,

bill

"brian.mills" <br********@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
No it still doesnt call it for the control on the user controls.

It does however If I use a normal ASP textbox control.

Do I have to call the load post back data from the page, call it for each
usercontrol, and then call it for each control on the user control? Or how
does it get subscribed to?

Nov 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Burke | last post by:
I am getting a curious problem where LoadPostData is not being called after registering the control using RegisterRequiresPostback. Other controls not requiring postback registration are having...
0
by: One Handed Man \( OHM - Terry Burns \) | last post by:
I have implemented the System.Web.UI.IPostBackDataHandler.LoadPostData interface in my custom control, however, when I submit this Function is not called by ASP.NET ( Which is what I assume is...
6
by: Francois | last post by:
Hi, I am trying to implement a custom control that extends the standard System.Web.UI.WebControls.CheckBox control. In the .Net class library reference it is said that CheckBox Implements...
0
by: Charlie | last post by:
I am building a custom webcontrol that has several internal textboxes. To restore the values in a postback, I use PostDataCollection(PostDataKey) from within the LoadPostData function. ...
1
by: z f | last post by:
Hi. How can I make a custom control in VB.NET that is inheriting from TextBox and also implements/inherits the IPostBackDataHandler? the problem is that in VB.NET I can't inherit from more that...
0
by: Martin Gustavsson | last post by:
I'm a bit puzzled by the IPostBackDataHandler. What if i have a custom control that I render myself, and I render 30 input-fields. They can't all have the name of the control's UniqueID? Which is...
4
by: Nathan Sokalski | last post by:
During my postbacks, I try to assign the value from an Input tag to a property of a custom control. However, I keep recieving the following error: An exception of type...
0
by: mankuipeng | last post by:
I am doing ActiveReports with .NET environment. There is a ASP.NET page, with custom control on it. Control displays data from database, by editing all the necessary data and click 'Submit' button to...
4
by: Piotr Nowak | last post by:
Hi, Im developing a RibbonBar Control in asp.net 1.1 by converting already done in asp.net 2.0. My problem is that theres no compositecontrol in 1.1. Correct me if im wrong, heres what i want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.