开发者

User Control losing properties on postback

I have a user control which has a number of properties. This user control is placed inside a TemplateField of a GridView, and the properties are databound from the grid's datasource. On the user control I have some LinkButton's which carry out actions, using some o开发者_如何学JAVAf the properties as properties (e.g. I pass in a row's ID)

The values go into it fine, but as soon as the LinkButton is clicked on the usercontrol, the properties reset to null so the LinkButton action doesn't work. What could cause this? I have made sure ViewState is enabled.

EDIT: Some code:

Properties:

public long? _InvoiceID;
[PersistenceMode(PersistenceMode.Attribute)]
[Bindable(BindableSupport.Yes)]
public long? InvoiceID {get { return _InvoiceID; } set { _InvoiceID = value; } }


try to save values you passed to user control into Hidden fields within your user control and when you click the LinkButton read the hidden field value

Update

the variable long? _InvoiceID is a stateless so you can try this

[PersistenceMode(PersistenceMode.Attribute)]
[Bindable(BindableSupport.Yes)]
public long? InvoiceID 
{
   get { 
         return (long?)_InvoiceIDHiddenn.Value; 
       } 
   set {
          _InvoiceIDHiddenn.Value = value; 
       } 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜