c# - Enable and disable Control on database value change -
i have situation have disable controls on database value change.
for have used following code.
here disabling controls in panel on 0 value , on other values enabling it.
using system; using system.collections.generic; using system.data; using system.data.sqlclient; using system.linq; using system.text; using system.web; using system.web.script.serialization; using system.web.ui; using system.web.ui.webcontrols; public partial class test_control : system.web.ui.page { string test1; list<double> _data = new list<double>(); public datatable dt = new datatable(); protected void page_load(object sender, eventargs e) { getdata(); } private void getdata() { int maxid; using (sqlconnection dataconnection = new sqlconnection("data source=localhost\\sqlexpress;initial catalog=mcas;integrated security=sspi")) using (sqlcommand datacommand = new sqlcommand("select top 1 runmode mcasmonitoring_rev1 order id desc", dataconnection)) { dataconnection.open(); maxid = convert.toint32(datacommand.executescalar()); textbox1.text = maxid.tostring(); if (textbox1.value == 0) { panel1.enabled = false; } else { panel1.enabled = true; } } } }
but situation have refresh page achieve operation. want need in runtime without refreshing entire page.
snpandya....
suggestion 1
panels should disable based on db values...so once have come across server side. now, once have db values can call javascript serverside , disable controls want........
suggestion 2
put controls inside "updatepanel" not feel page postback
Comments
Post a Comment