How to programatically unbind a web control?

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!
 
S

Stefano Mostarda

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
 
J

John Saunders

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.
 
B

Bobby Ryzhy

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
 
G

Gromit

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top