|
This the code to initialize a button control that I have on my page:
Sub Page_Load(ByVal Sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
SQLconn.Open()
Dim SelectCmd1 As New SqlCommand("SELECT [rawvalue] FROM [Data] WHERE (timestamp=(SELECT MAX(timestamp) FROM [Data]WHERE(name = 's1'))) AND (name='s1')", SQLconn)
SelectCmd1.CommandType = CommandType.Text
Dim result1 As Integer
Dim myDataReader1 As SqlDataReader
myDataReader1 = SelectCmd1.ExecuteReader()
myDataReader1.Read()
result1 = myDataReader1.GetInt32(0)
SQLconn.Close()
ChangeButton1(result1)
End If
End Sub
Sub ChangeButton1(ByVal Status As Integer)
If Status = -1 Then
Label1.Text = "ON"
OnOff1.Style.Value = "background-image: url(../ImgContr/1.png);"
Else
Label1.Text = "OFF"
OnOff1.Style.Value = "background-image: url(../ImgContr/2.png);"
End If
End Sub
Also I use to write to the database:
Sub OnOff_Click1(ByVal Sender As Object, ByVal e As System.EventArgs)
Dim updateCMD As SqlCommand
Dim query As String
If Label1.Text = "ON" Then
query = "UPDATE [Triggers] SET [rawvalue] = 'False' WHERE [name] = 's1'"
ChangeButton1(0)
Else
query = "UPDATE [Triggers] SET [rawvalue] = 'True' WHERE [name] = 's1'"
ChangeButton1(-1)
End If
updateCMD = New SqlCommand(query, SQLconn)
updateCMD.CommandType = CommandType.Text
SQLconn.Open()
updateCMD.ExecuteNonQuery()
SQLconn.Close()
End Sub
I used Ajax Update Panel with my button(OnOff1) inside to write the to the database without reloading the page.
What I want now is to poll the database every few seconds to read the values without pressing refresh(F5).
I believe that I have to use the Ontick event of the Update Panel Trigger and a asp Timer control.
How should I modify the Sub for Page_Load Event?
|
|
|
|
|
You need to write some javascript. Use the setInterval function to call your server-side method and get the refreshed data. Then you can refresh the control used to display your data.
Another tip: Stop using dynamic SQL statements! Use stored procs ro at least validate the values used to build your statements.
only two letters away from being an asset
|
|
|
|
|
Do you have any examples for the javascript?
I will use dynamic SQL statements only for testing.
Thank you for your tips.
|
|
|
|
|
kallileo wrote: I will use dynamic SQL statements only for testing.
Yeah, I've heard that many times.
So you plan on writing two different versions of your code, one for testing and one for production? Can we guess at how reliable and maintainable that solution will be.
As for the javascript, do a search for setInterval
only two letters away from being an asset
|
|
|
|
|
It's for presentation only. I'm a student and I neen it as a Interface to control a hardware device in my project.
Is javascript realy necessary?
I was thinking of using asp timer control with an interval and the OnTick event of the triggers in the update control to call the Sub to refresh the page.
Thank you.
|
|
|
|
|
kallileo wrote: I'm a student
Then you should be learning the proper way to code.
kallileo wrote: Is javascript realy necessary?
AJAX = Asynchronous JAVASCRIPT and xml
At some point if you are using AJAX you will need to learn it. No it isn't strictly necessary in your case, although I think it is easy to use then what you trying.
-- modified at 11:52 Tuesday 12th June, 2007
only two letters away from being an asset
|
|
|
|
|
Dear all,
I am using Visual Studio2005.
Everything was working fine till I tried to set default error page for web application
(that is through ASP.NET Configuration I used ->application tab, set default error page)
Then after I am getting stating Unable to start Debugging on the web server
I restart iis and even reinstall the IIS problem continue.
Please help
thanks
regards
imran khan
|
|
|
|
|
Hi, I'm using this popup control:
http://www.codeproject.com/aspnet/asppopup.asp[^]
And I'm having a problem where someone clicks on a button on the page to make a DB update, the popup tells them it was successful. If they then click a link and go to another page, then click on the back button, the popup control fires again, even though there was no DB update the second time.
Can anyone help with a solution to this problem please?
Thanks,
Statia
|
|
|
|
|
Most likely the script for popup script is being inserted into the page during the butten click event. When using the back button this code is still in the page. You have to figure out where and how to disable it when a DB update is not necessary.
only two letters away from being an asset
|
|
|
|
|
function codename() {
if(document.formname.checkboxname.checked)
{
document.formname.textname.disabled=false;
}
else
{
document.formname.textname.disabled=true;
}
}
hi friens this is my javascript code with checkbox,button
here i select checkbox the button is enabled and deselect it is disabled(it is working fine)
now i am using html page
<asp:checkbox id="checkboxname
onclick="codename()"" runat="server">
<asp:button id="textname" disabled="" size="1" runat="server""> (it is not working)
i gave runat=server in html..(it is also not working)
can u help me
|
|
|
|
|
if you are using runat=server for any control then defin the tag like
in javascript method use like following
document.getElementById("whateverID").checked
Regards,
Sylvester G
sylvester_g_m@yahoo.com
|
|
|
|
|
If you use runat=server then the name will be changed better see in viewsource or/use
document.getElementById(CustomerInfo").Checked
or try this also
document.forms[0]["checkbox1"].checked
|
|
|
|
|
hi
it is not working
if possible give the code.plz
|
|
|
|
|
function codename() {
if(document.form[0][checkboxname].checked)
{
document.form[0][textname].disabled=false;
}
else
{
document.form[0][textname].disabled=true;
}
}
|
|
|
|
|
What exactly isnt' working? Are you getting an error?
|
|
|
|
|
If you use runat="server" you need to create javascript variables to hold the client side Id, which is represented by the ClientID property, and is not the Id you set on the server side.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Christian Graus.
So How can we get CientID of any server control?
Bajrang Singh
Using .net 2.0 (VS2005)
|
|
|
|
|
Hi all,
I am working on a project in which I have used Telrik TreeView control But I want to scroll the page when I am draging a node and droping on a node.Reply me If u have any way of it..
Thanks
Sapan Roy
Hi all go for this...
|
|
|
|
|
Hi Sapan,
Better u browse telerik.com and post a thread in the forum.
Its not correct to ask here.
Hope u will succeed
Have a Nice Day Dude
|
|
|
|
|
Hi friends..plz go through this pseudo code
I Included Requirid Namespaces
Dataset ds;--------------------------------------1
//static Dataset ds;-----------------------------2
protected void page_load(parameters)
{
ds = function in Data acesss Layer which retrives records from database and returns dataset.
populatedatagrid();
}
void populatedatagrid()
{
if(mydropdownlist.selectedIndex=0)
datagrid1.datasource=ds;
else
{
datagrid1.Datasource= here I performed filtering action using Row Filter Property and selected Index Value
}
}
void mydropdownlist_selectedIndexchanged(parameters)
{
populatedatagrid();
}
I am designing a web page where by default all records will displayed.but by selecting from dropdownlist I can filter the records.Later I thought its not right to perform the fuctionalities of the page_load event at each postback(unnecessry making connection to the database)..so i used Page.Ispostback to avoid that..so first time it worked fine but when i selected from dropdwn list it throws an error "object reference not set to an instance of object"..
reason for above error i understood(because in page load event i am returning dataset which does not happened at page post back)..so one of my friend commented the line no-1 and uncommented the line no-2 in above code..thus made dataset static..and it works
What I am not understanding is why making the dataset static solved the task..though HTTP is static?Is making dataset ststic makes the records to be saved at server?
Warm Regards,
Rahul Agarwal
-- modified at 7:11 Tuesday 12th June, 2007
|
|
|
|
|
change the property of dropdownlist autopostback property to TRUE and try
|
|
|
|
|
Change dropdown property autopostback to TRUE
|
|
|
|
|
Please note that you have an option to modify your message.
And what the PostBack property is going to do with the Question?
Regards,
Arun Kumar.A
|
|
|
|
|
Please don't use static unless you are sure that it will not create any side effect.
Consider the following program:
<code>static int i;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
i=i+1;
TextBox1.Text=i.ToString();
}
</code>
For each Button Click event, the value of "i" is incremented and displayed in the TextBox.
I have clicked the button 5 times and the text box shows 5 in it.
At this moment,when I opened another browse , copy - paste the same url
and I tried to click the button, it shows "6" in it.
So, I think that:
For the first request, an Object of the page is created and maintained in the server.
For subsequent request separate object is created for the page and is rendered to the Client,
and the static member is shared by all objects.
Regards,
Arun Kumar.A
|
|
|
|
|
Thanks a lot Arun..u understood my question..and answered precisely..
|
|
|
|