How to programatically unbind a web control?

  • Thread starter Thread starter Gromit
  • Start date Start date
G

Gromit

Hi,

Apologies for the cross posting, but I sent this into the web controls
board 10 days ago and unluckily for me no-one picked it up. I'd really
appreciate any ideas, because I'm quite stuck on this one. Thanks!

I have a bunch of controls that have their initial values bound to
database values. On saving, I want the new values the user has selected
to update the datbase values, but the binding seems to prevent the
update. When I don't use selected value binding, everything is fine.

Is there a way of 'unbinding' the controls in the moments after the save
button has been clicked to allow the new values to be updated? Or is
there a better way of achieving what I'm trying to do?

Thanks again for any thoughts,

Gromit






*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Hi,

It looks like you rebind your control against DB each postback.

Bind them only the first time using

If (!Page.IsPostBack) BindControls();

HTH,
Stefano Mostarda MCP
Rome Italy
 
Gromit said:
Hi,

Apologies for the cross posting, but I sent this into the web controls
board 10 days ago and unluckily for me no-one picked it up. I'd really
appreciate any ideas, because I'm quite stuck on this one. Thanks!

I have a bunch of controls that have their initial values bound to
database values. On saving, I want the new values the user has selected
to update the datbase values, but the binding seems to prevent the
update. When I don't use selected value binding, everything is fine.

Is there a way of 'unbinding' the controls in the moments after the save
button has been clicked to allow the new values to be updated? Or is
there a better way of achieving what I'm trying to do?

Rebind the controls instead. Call DataBind after you've changed the
database. Depending on what changed, you may even want to requery the
database at this time.
 
Make sure that you are only doing the bind if it isnt a post back.

example:
protected System.Web.UI.WebControls.TextBox t = new TextBox();
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
DoControlBinding();
}

private void DoControlBinding()
{
t.DataBind();
}

Bobby Ryzhy
(e-mail address removed)
http://www.weekendtech.net
 
Thanks a million to everyone who posted on this.

The code that worked for me in VB is this

If Not (Page.IsPostBack) Then
DataBind()
End If

Cheers,

Graham

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Back
Top