|
I'm sorry in advance because I'm very new to this. I think I've done a decent job doing my homework first though. I've searched what seems like everywhere for an answer before posting here but I've found nothing that does exactly what I'm hoping for.
Using developer 2005 with C# as my primary language.
What I want to do is be able to execute code when the user closes the web page very similar to a FormClosing event in a windows application. Is this not possible?
Two things I've sort of ruled out are:
Using Global.asax and session_end doesn't seem to work because I don't think I'll have access to my other methods that way(session_end seems sort of iffy anyway from what I've read).
Form_Unload fires everytime the user switches between pages(which I don't want)
Any advice appreciated.
|
|
|
|
|
No, it's not possible. The web is disconnected, what someone does on the browser, you have no idea. I think you can set something up in javascript, but I don't think it's reliable.
your C# code has nothing to do with the users actions, except when the user does something that creates a postback or a page request. Closing the browser does neither.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
You can use onunload event handler of <body> object, and send some specific request to server in it - it can be implemented as synchronous XMLHTTP request.
I have seen several applications which performs logout procedure in this way.
|
|
|
|
|
Hi everybody, it's me again(SPIKE). Did anyone of you know how to keep the dropdownlist control behind a pop up menu? I just downloaded the control from this Site and I can't seem to fix it; and, if it's not too much trouble, could you help me adding buttons to the pop up menu to use it like a MSGBOX(I'm talking about yes-no questions).
You can send your answers to spikereloaded@gmail.com. PLEASE HELP ME.
Spike reloaded
|
|
|
|
|
Hi, Spike. I suspect you read SOME of my earlier reply, as your subject/header is at least sensible now. Just to remind you of my other points:
1 - if you have a question about an article, you should ask it to the article auther ( that is, in the forum for the article ). This site has lots of articles, from lots of people. Not all of them necessarily still read the site, or read it often enough to see this. They will get an email if you ask in the right place.
2 - This is a limitation of many javascript driven menus, you may just need to find one that doesn't do that.
Thanks for playing.
James_Marsters wrote: You can send your answers to spikereloaded@gmail.com.
No-one will do that. For starters, it gives you someone's email address, when perhaps they don't want to offer it. Secondly, why would we want to go out of our way to help someone who seems to be saying they aren't going to come back to check the site ?
In any case, if you gave this email in your profile, you'll get an email from any answers, as you'd have found when I replied to you on the site last time.
It's also not good to put your email address like that. CP will never spam you, but the site can't stop bots from searching the text in the forums for email addresses, for spam lists.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hey:
I am facing problem in my asp.net/vb.net 2.0 program. i want to Select,Add, Delete,Edit,Update,Cancel. Ineteresting thing is that Event is working except Update,Delete Gridview Without inserted data into database.
my requirement is to add multiple Items in gridview and after successful data entry and in last, i want to save gridview all rows at once, not one by
one.
i place two/three textboxes followed by add button which will add textbox values in to gridview (Note: Not in Database), if due to any entry error, i simply want to edit,update/delete inserted rows from the gridview.
Note: Gridview EditColumns , i add two boundfields and then converted to Templatefiled and i have unchecked auto generate fields becoz i dont wana any extra fields. finally when i press Post button it will post all gridview data rows once and Problem is update/delete datagrid before post the data into the database, may be update/delete i will add more values in gridview and then post. i think enough description to tell someone wat i actually wants. in advance thankyou to help me out.
Note: just right the code on request area and reply me back. once again thank you. remember i am new to asp.net and vb.net and please do it only in asp/vb.net
i am pasting my code below, please help me out how i can do this on fly,please dont forget to lable the code.
Here is my Code
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports System.Configuration
Imports System.Collections
Partial Class _Default
Inherits System.Web.UI.Page
Dim dt As Data.DataTable
Dim ds As New Data.DataSet
Dim ds1 As New Data.DataSet
Dim dr As Data.DataRow
Dim dc As New Data.DataColumn
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SqlCon As New SqlConnection
Dim SqlCom As SqlCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SqlCon.ConnectionString = System.Configuration.ConfigurationManager.AppSettings.Get("alisons")
'SqlConnection("Data Source=dell;Initial Catalog=alisons;Integrated Security=True")
'cn.Open("Dsn=alisons; uid=alisons; pwd=alisons;")
dt = New Data.DataTable
ds = New Data.DataSet
If Not IsPostBack Then
Session("ds") = ds
ds.Tables.Add(dt)
ds.Tables(0).Columns.Add(New Data.DataColumn("Code"))
ds.Tables(0).Columns.Add(New Data.DataColumn("Name"))
ds.AcceptChanges()
End If
End Sub
Sub fillGrid()
ds1 = CType(Session("ds"), Data.DataSet)
GridView1.DataSource = ds1.Tables(0)
GridView1.DataBind()
End Sub
Protected Sub cmdAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
ds1 = CType(Session("ds"), Data.DataSet)
dr = ds1.Tables(0).NewRow()
dr("Code") = Txt_Code.Text
dr("Name") = txt_Name.Text
ds1.Tables(0).Rows.Add(dr)
ds1.AcceptChanges()
fillGrid()
Txt_Code.Text = ""
txt_Name.Text = ""
End Sub
Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PageIndexChanged
fillGrid()
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
End Sub
Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
GridView1.EditIndex = -1
fillGrid()
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
' delete row
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.EditIndex = e.NewEditIndex
fillGrid()
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
' Facing Problem Here
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
' Facing Problem Here
'ds1 = CType(Session("ds"), Data.DataSet)
Dim GRow0 As GridViewRow = GridView1.Rows(e.RowIndex)
Dim GRow1 As GridViewRow = GridView1.Rows(e.RowIndex)
If Not GRow0 Is Nothing And Not GRow1 Is Nothing Then
Dim t0 As TextBox = GRow0.FindControl("texcol0")
Dim t1 As TextBox = GRow1.FindControl("texcol1")
'T = GRow.FindControl("Code")
If Not t0 Is Nothing And Not t1 Is Nothing Then
Response.Write("The Col0 is Entered " + t0.Text)
Response.Write("The Col1 is Entered " + t1.Text)
'dr = ds1.Tables(0).NewRow()
'dr("Code") = t0.Text
'dr("Name") = t1.Text
'ds1.Tables(0).Rows.Add(dr)
ds1.AcceptChanges()
'fillGrid()
End If
End If
End Sub
Protected Sub btnPost_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPost.Click
'Dim ds1 As DataSet = CType(Session("ds"), DataSet)
'Dim datasource1 As SqlDataSource = New SqlDataSource()
Dim paramCode As String
Dim paramName As String
Dim sqlstr As String
Dim dr As DataRow
Dim datasource1 As SqlDataSource
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
datasource1 = New SqlDataSource()
ds1 = CType(Session("ds"), Data.DataSet)
cn.Open("DSN=alisons; uid=alisons; pwd=alisons;")
Response.Write(cn)
If cn.State = 1 Then
'cn.BeginTrans()
For Each dr In ds1.Tables(0).Rows
paramCode = Trim(dr("Code"))
paramName = Trim(dr("Name"))
sqlstr = "INSERT INTO Tbl_LOV(Code, Name) VALUES ('" + paramCode + "','" + paramName + "')"
cn.Execute(sqlstr)
Next
'cn.CommitTrans()
Response.Write("Inserted")
End If
End Sub
Protected Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
GridView1.EditIndex = -1
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
End Sub
End Class
-----------------------------------------------------------------------------
Regards,
Ricky.
|
|
|
|
|
Hi All...
I have a login page(page1) that checks the user name and his password for a user, when the authorized user goes into the next page(page2)-I initialize an (ID session) and then when he loggs off I empty the session...
but, by the back button he could return back again to the 2nd page (and this is the problem )...
Could you help me..
Thanks alot...
Nour
|
|
|
|
|
All your pages should check if the user is logged in, and if not, deny access.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I did that...
But what I need is not to allow the user to go back when back button is pressed...
Thanks
|
|
|
|
|
Well, to do that, you simply need to not serve the page if the security check fails. If they are not logged in, your base page should redirect to the login page.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I do that
but the problem is:
when an autherized user loggen in, and the logged out, he can press the back button and go again to the pages, although the sessions are empty...
regards
|
|
|
|
|
Well, then you don't 'do that' at all. If the session is empty, then the only way they can see the page is from the cache. And there's nothing you can do about that.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
|
you can design a base class to check the session is null or not, then all the pages you use to inherit the base class
|
|
|
|
|
I did that...
But what I need is not to allow the user to go back when back button is pressed...
Thanks
|
|
|
|
|
add following code in body tag
onload="history.forward(-1);"
|
|
|
|
|
I am using a datalist to easily display my data in 7 columns, but I can't seem to get the alignment correct. After a few tries i opened up the HTML and found border-collapse:collapse in the table's style. I used IE7s DevToolBar DOM viewer to remove it on the fly and everything looks and works great. So now my question is how do I get ASP.NET not to add it? I have tried using a CssClass, but the class option gets overwrote by the inline one. I also have tried to remove it after the fact with a little JavaScript (document.GetElementByID("elementID").style="" or document.GetElementByID("elementID").style.border-collapse="") both don't work. Thanks for any help.
|
|
|
|
|
Did you try the CellSpacing property?
Setting it to a positive value should remove the border-collapse style.
By the way, your javacript code is slightly wrong, try this:
document.getElementById("elementID").style.borderCollapse=""
But before doing such javascript stuff better try playing around with the border-related members of the DataList class.
Hope that helps
Klaus
|
|
|
|
|
Thanks, I've played with all the spacing and cell properties but none just remove the collapse (normally they added extra space I didn't want). Thanks for the javascript correction, I hate when javascript and CSS use different property names.
|
|
|
|
|
The exact effects of the ASP Class members to html output is poorly ducumented. Perhaps I'll find sth more exactly on google. I'll let you know.
Good Luck
Klaus
|
|
|
|
|
my windows dos not have IIS - (its not listed at Control Pannel/Add or Remove Programs/Add-Remove Windows Components/Windows Components Wizard list)
its Windows-Home edition service pack 2 -
can i install IIS from any where or i should shift to another windows? - if so,what version?
tx.
|
|
|
|
|
Running IIS on Windows Home Edition is not "officially" supported by Microsoft however it is possible to run it if you tweak some settings.
Please know however that tweaking these settings can severely cripple your machine so be prepared to reinstall your machine if anything goes wrong.
Check out this site for more info:
http://adamv.com/dev/articles/iis-on-xp-home[^]
If you don't want to get into messing around with registry files however, Windows Professional Edition is the version you'll want to get. It has IIS installed (which is the only way to run asp.net web sites on your local machine).
Good luck.
-Goalie35
|
|
|
|
|
This is not what you asked for, but perhaps the information you need...
If you are using Visual Studio 2005 you don't need IIS to test your web applications. It comes with a built in web server that is used when you start the application from Visual Studio.
---
Year happy = new Year(2007);
|
|
|
|
|
Hello folks,
I have a problem using ASP.NET 2.0 on IIS 6. I use a self made login routine using session variables. An object is stored in Session["user"] for this purpose. While on a test system everything works fine, on the real server the session variable disapears. This can happen within seconds or a few minutes while clicking around on the web site. Can't say anything more spcific. Does anyone know what can cause this problem?
Perhaps wrong server settings? If so, which?
Thx Klaus
|
|
|
|
|