473,659 Members | 3,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with Databinding during PreRender

Hi all,

I have a piece of XML that looks like this, which I want to DataBind
to a Repeater (the Repeater is inside a UserControl):

<SECTION id="MAIN" >
<SUBSECTION id="SUB1" />
<SUBSECTION id="SUB2" />
<SUBSECTION id="SUB3" />
</SECTION>

The Repeater definition looks like this:

<asp:Repeater id="rpt1" runat="server">
<ItemTemplate >
<asp:LinkButt on id="lbtnSubSect ion" runat="server"
EnableViewState =False CommandName=<%#
((System.Xml.Xm lNode)Container .DataItem).Attr ibutes["id"].Value %>
OnCommand="Link Button_SubSecti onCommand"><%#
((System.Xml.Xm lNode)Container .DataItem).Attr ibutes["id"].Value
%></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>

I bind the Repeater to the XmlNodeList using this code in
Page_PreRender:

XmlNodeList dataSourceNodeL ist =
myPieceOfXML.Se lectNodes("SUBS ECTION");
rpt1.DataSource = dataSourceNodeL ist;
rpt1.DataBind() ;

I have to do this in PreRender because the piece of XML may change
depending on a button I have clicked earlier, so I have to evaluate
this Click event before I can do the DataBind.

Once rendered the HTML looks like this:

<a id="uc1_rpt1__c tl1_lbtnSubSect ion"
href="javascrip t:__doPostBack( 'uc1$rpt1$_ctl1 $lbtnSubSection ','')">SUB1</a>
<a id="uc1_rpt1__c tl2_lbtnSubSect ion"
href="javascrip t:__doPostBack( 'uc1$rpt1$_ctl2 $lbtnSubSection ','')">SUB2</a>
<a id="uc1_rpt1__c tl3_lbtnSubSect ion"
href="javascrip t:__doPostBack( 'uc1$rpt1$_ctl3 $lbtnSubSection ','')">SUB3</a>

Upon postback it becomes clear that the CommandName property has not
been properly bound (e.CommandName evaluates to "") but the Text
property of the LinkButton has, even if they point to the same XML
attribute (id)! This does not happen if I put the code in Page_Load.
Why is this? Can anyone suggest a workaround?

Cheers, Eva
Nov 18 '05 #1
3 2599
"Musravus" <ev********@hot mail.com> wrote in message
news:be******** *************** *@posting.googl e.com...
Hi all,

I have a piece of XML that looks like this, which I want to DataBind
to a Repeater (the Repeater is inside a UserControl):

<SECTION id="MAIN" >
<SUBSECTION id="SUB1" />
<SUBSECTION id="SUB2" />
<SUBSECTION id="SUB3" />
</SECTION>

The Repeater definition looks like this:

<asp:Repeater id="rpt1" runat="server">
<ItemTemplate >
<asp:LinkButt on id="lbtnSubSect ion" runat="server"
EnableViewState =False CommandName=<%#
((System.Xml.Xm lNode)Container .DataItem).Attr ibutes["id"].Value %>
OnCommand="Link Button_SubSecti onCommand"><%#
((System.Xml.Xm lNode)Container .DataItem).Attr ibutes["id"].Value
%></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>

I bind the Repeater to the XmlNodeList using this code in
Page_PreRender:

XmlNodeList dataSourceNodeL ist =
myPieceOfXML.Se lectNodes("SUBS ECTION");
rpt1.DataSource = dataSourceNodeL ist;
rpt1.DataBind() ;

I have to do this in PreRender because the piece of XML may change
depending on a button I have clicked earlier, so I have to evaluate
this Click event before I can do the DataBind.

Once rendered the HTML looks like this:

<a id="uc1_rpt1__c tl1_lbtnSubSect ion"
href="javascrip t:__doPostBack( 'uc1$rpt1$_ctl1 $lbtnSubSection ','')">SUB1</a> <a id="uc1_rpt1__c tl2_lbtnSubSect ion"
href="javascrip t:__doPostBack( 'uc1$rpt1$_ctl2 $lbtnSubSection ','')">SUB2</a> <a id="uc1_rpt1__c tl3_lbtnSubSect ion"
href="javascrip t:__doPostBack( 'uc1$rpt1$_ctl3 $lbtnSubSection ','')">SUB3</a>
Upon postback it becomes clear that the CommandName property has not
been properly bound (e.CommandName evaluates to "") but the Text
property of the LinkButton has, even if they point to the same XML
attribute (id)! This does not happen if I put the code in Page_Load.
Why is this? Can anyone suggest a workaround?


Eva, does the same thing happen if you use quotes around the CommandName
value? I believe you'll have to use single quotes around 'id'.

Also, have you tried doing the DataBind within the click event?
--
John Saunders
johnwsaundersii i at hotmail
Nov 18 '05 #2
Hi,

You should enable the viewstate for your link buttons; since command name
property is being 'programmatical ly' modified, it must be persisted on the
client.

Cosmin

"Musravus" <ev********@hot mail.com> wrote in message
news:be******** *************** *@posting.googl e.com...
Hi all,

I have a piece of XML that looks like this, which I want to DataBind
to a Repeater (the Repeater is inside a UserControl):

<SECTION id="MAIN" >
<SUBSECTION id="SUB1" />
<SUBSECTION id="SUB2" />
<SUBSECTION id="SUB3" />
</SECTION>

The Repeater definition looks like this:

<asp:Repeater id="rpt1" runat="server">
<ItemTemplate >
<asp:LinkButt on id="lbtnSubSect ion" runat="server"
EnableViewState =False CommandName=<%#
((System.Xml.Xm lNode)Container .DataItem).Attr ibutes["id"].Value %>
OnCommand="Link Button_SubSecti onCommand"><%#
((System.Xml.Xm lNode)Container .DataItem).Attr ibutes["id"].Value
%></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>

I bind the Repeater to the XmlNodeList using this code in
Page_PreRender:

XmlNodeList dataSourceNodeL ist =
myPieceOfXML.Se lectNodes("SUBS ECTION");
rpt1.DataSource = dataSourceNodeL ist;
rpt1.DataBind() ;

I have to do this in PreRender because the piece of XML may change
depending on a button I have clicked earlier, so I have to evaluate
this Click event before I can do the DataBind.

Once rendered the HTML looks like this:

<a id="uc1_rpt1__c tl1_lbtnSubSect ion"
href="javascrip t:__doPostBack( 'uc1$rpt1$_ctl1 $lbtnSubSection ','')">SUB1</a> <a id="uc1_rpt1__c tl2_lbtnSubSect ion"
href="javascrip t:__doPostBack( 'uc1$rpt1$_ctl2 $lbtnSubSection ','')">SUB2</a> <a id="uc1_rpt1__c tl3_lbtnSubSect ion"
href="javascrip t:__doPostBack( 'uc1$rpt1$_ctl3 $lbtnSubSection ','')">SUB3</a>
Upon postback it becomes clear that the CommandName property has not
been properly bound (e.CommandName evaluates to "") but the Text
property of the LinkButton has, even if they point to the same XML
attribute (id)! This does not happen if I put the code in Page_Load.
Why is this? Can anyone suggest a workaround?

Cheers, Eva

Nov 18 '05 #3
Got it... It's actually really simple - I had EnableViewState set to
false for those controls that did not bind properly. Apparently this
influences the way the databinding process works. It kind of makes
sense when you think of it.

Thanks all for your suggestions. You were correct. FYI I did find a
workaround, by placing a hidden input variable inside the
<itemtemplate > tag, like this:

<asp:Repeater id="rpt1" runat="server">
<ItemTemplate >
<asp:LinkButt on id="lbtnSubSect ion" runat="server"
EnableViewState =False
OnCommand="Link Button_SubSecti onCommand"><%#( (System.Xml.Xml Node)Container. DataItem).Attri butes["name"].Value%></asp:LinkButton>
<input type=hidden runat=server
value=<%#((Syst em.Xml.XmlNode) Container.DataI tem).Attributes["id"].Value%>
id=hdSubSection >
</ItemTemplate>
</asp:Repeater>

This renders correctly - I reckon the "Value" attribute is a render
property so it binds correctly during Page_PreRender, whereas the
"CommandNam e" attribute is something that needs to be bound earlier,
like in Page_Init or Page_Load.
Upon postback, in my Command event code after a click on one of the
Repeater's LinkButtons, I can then get hold of the "id" value by
accessing the hidden variable's Value:

LinkButton controlClicked = (LinkButton) sender;
HtmlInputHidden hiddenVar =
(HtmlInputHidde n)controlClicke d.Parent.FindCo ntrol("hdSubSec tion");
string id = hiddenVar.Value ;

This I can then use in Page_PreRender to create the XML to re-bind to
the Repeater. Sweet music.
Nov 18 '05 #4

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

Similar topics

0
1200
by: Thomas | last post by:
I have a dropdownlist whose items are bind to it during runtime. I do it in the databinding event, but the event handler was never get called. Finally I have to do the databinding in the prerender event. Has anyone had a similar problem? Thanks,
2
1353
by: BluDog | last post by:
Hi I have a created a custom web control called ImageBrowser, extract is below: <Code> #Region "Properties" Public Property Images() As ImageCollection
5
1516
by: Peter Rilling | last post by:
I have an interesting issues that, although I not blocking me, is not very performance. Maybe someone can suggest a better way of doing this. 1) I have a page that displays a grid with command links such as Delete. Obviously if this link will delete the item of the current line. 2) The grid is initialized during the Init event so that the events can be bound. It is my understanding that events do not get fired unless the object...
2
1678
by: Al Smith | last post by:
I kind of understand how the below works, however I am trying to do it at runtime vrs design time. <asp:TextBox id="TextBox1" runat="server" Text='<%# StateList.SelectedItem.Text %>'></asp:TextBox> So what I really want to do is something like I show below. In Page_Load I have: TextBox txt; txt= new TextBox();
4
1647
by: Nathan Sokalski | last post by:
I have two databinding expressions (the first & last names from a DB) that I want to assign to the text property of a Label so that the result is LASTNAME,FIRSTNAME. At the moment, I have the following which I know works when I use it by itself: text='<%# DataBinder.Eval(Container,"DataItem.membernames.lname") %>' What I need to do is somehow concatenate this databinding expression, a comma, and another databinding expression for the...
8
2175
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got answered... In 1.1 we always did our own myDataAdapter.fills and we liked that control for lots of good reasons. Now the new DataSource (or is it a TableAdapter:Dataset) automatically fills the Gridview. How can we control that fill? In a...
9
24784
by: J055 | last post by:
Hi I have a very simple configuration of the GridView with paging and sorting. When I do a postback the DataBinding event fires twice - in both the ProcessPostData and PreRender stages of the page life cycle. In this example the event fires twice when a) GridView EnableViewState=False and any image type control in the <columns/> element. When either EnableViewState is set to true or the image button is removed, the event fires once....
9
2307
by: Nathan Sokalski | last post by:
I have a very simple UserControl which contains an Image and a Label, which I use to display an image with a caption. I am using this control inside a DataList, setting the two Public variables using attributes in the *.aspx page. Everything displays great for the initial load, but whenever I try to add or delete an item (I have controls to do this on the page), it does not seem to be recieving any values for the public variables. Here is...
2
1278
by: Sebastian | last post by:
Hi, I want to skin the templates of an asp:DataList. So I have to do data binding in the skin (I didn't find another comfortable way to do that). As soon there's a <%# ... %tag in the skin, VS seems not to recognize the skin file anymore. The property editor displays SkinID grayed out, and I cannot select anything. Interestingly, I can enter the SkinID by hand, and page rendering actually works!
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.