By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,144 Members | 1,286 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,144 IT Pros & Developers. It's quick & easy.

How to programatically unbind a web control?

P: n/a
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!
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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 wrote:
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!

Nov 18 '05 #2

P: n/a
"Gromit" <Anon> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
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.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #3

P: n/a
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
bo***@weekendtech.net
http://www.weekendtech.net

On Thu, 08 Jul 2004 13:43:34 -0700, Gromit <Anon> wrote:
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!


Nov 18 '05 #4

P: n/a

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!
Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.