|
Hi,
Thanks, it work fine, but can I know how to close this dialog box as I'd tried window.close but it doesn't work instead it open up a new window :P
J Liang
|
|
|
|
|
Hi,
Sorry, forgot to add this reply, I was wondering how can I return text value from the dialog box back to the parent window when it close?
J Liang
|
|
|
|
|
|
Hey,
Thanks, it's working fine.
J Liang
|
|
|
|
|
I've got an aspx page that contains a combo box with a selectedindexchanged event hooked up. My page also needs some javascript contained in an include file. Every time I select an item from the combobox i get an error:
__doPostBack is undefined.(reported by firebug(IE was much less helpful))
The code in the included js file is working and if i remove the reference to the included file the postback works ok. I've checked that i should be able to use multiple script tags in a document and that seems like it should work.
What do i have to do to get both scripts running at the same time?
Thanks
Russell
<head id="ctl00_DocHeader"><link href="FormStyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="account.js" />
<title>
</title></head>
<body>
<form name="aspnetForm" method="post" action="AccountViewer.aspx" id="aspnetForm">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="<very long string>" />
</div>
<script type="text/javascript">
<!--
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>
|
|
|
|
|
This is the code in my login.ascx file.
<%@ Import Namespace="System.Data" %> <br />
<%@ Import Namespace="System.Data.Sql" %><br />
<%@ Import Namespace="System.Data.SqlClient" %><br />
<%@ Import Namespace="System.Data.SqlTypes" %><br />
<br />
<br />
<script language="C#" runat="server"><br />
<br />
public String RedirectPage ="Overzicht.aspx";<br />
<br />
public int chk;<br />
<br />
bool Authenticate(String user, String pass) <br />
{ <br />
bool authenticated = false;<br />
try <br />
{ <br />
String dsn = "server=localhost;uid=sa;pwd=;database=db";<br />
String sSQL = "SELECT emailadres,paswoord FROM tblPersoneelslid WHERE (emailadres='" + UserName + "' AND paswoord='" + Password + "')";<br />
<br />
SqlConnection Conn = new SqlConnection(dsn); <br />
SqlCommand Cmd = new SqlCommand(sSQL,Conn); <br />
SqlDataReader Read1 = null;<br />
<br />
Conn.Open();<br />
<br />
Read1 = Cmd.ExecuteReader(); <br />
<br />
if (Read1!=null){<br />
<br />
if (Read1.Read()) <br />
{ <br />
if (Read1.GetString(0)==user)<br />
{<br />
if(Read1.GetString(1)==pass){<br />
authenticated =true;<br />
}<br />
else<br />
{<br />
chk=1;<br />
}<br />
}<br />
else<br />
{<br />
chk=2;<br />
}<br />
}<br />
}<br />
<br />
}<br />
catch(Exception e) <br />
{<br />
Response.Write("Foutmelding: " + e.ToString());<br />
}<br />
<br />
return authenticated;<br />
}<br />
<br />
private void SubmitBtn_Click(Object sender, EventArgs e) <br />
{ <br />
if (Authenticate(UserName.Text, Password.Value)) <br />
{ <br />
Response.Redirect(RedirectPage);<br />
}<br />
<br />
else <br />
{<br />
if (chk==1)<br />
{<br />
Message.Text="Paswoord ongeldig";<br />
UserMark.Visible = false;<br />
PasswordMark.Visible = true;<br />
Message.Visible = true;<br />
}<br />
else<br />
{<br />
Message.Text="Gebruikersnaam ongeldig";<br />
PasswordMark.Visible = false;<br />
UserMark.Visible = true;<br />
Message.Visible = true;<br />
}<br />
}<br />
}<br />
<br />
</script>
and the error i get is:
Foutmelding: System.Data.SqlClient.SqlException: Login failed for user 'sa'. at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at ASP.login_ascx.Authenticate(String user, String pass) in d:\[ STAGE ]\Applicatie\WorkflowLibrary1\WebSite1\login.ascx:line 28
can someone help me with this problem?
-- modified at 4:07 Tuesday 24th April, 2007
|
|
|
|
|
Problems I noticed:
1. You're trying to log on to an SQL Server with 'sa' credentials.
2. You're code is open for SQL Injection.
3. SqlConnection should be opened in a try-catch block.
4. SqlDataReader should be closed after you retrive the data (either explicitly, or by specifíing the whole thing in a using statement.)
5. You just check is the SqlDataReader is created, but not if there's anything to read, so if there's no data, the GetString method will throw an excpetion.
6. You're using an unnecessary global variable chk.
7. You're shouldn't specify if the username or the password was incorrect. Just use some generic error message.
8. Don't let the user see the stack trace of an exception if thrown.
|
|
|
|
|
ty for the answer, but i have a new question now, i looked up for some new code and found this:
my login.aspx file:
<%@ Page Language="C#" %><br />
<%@ Import Namespace="System.Data" %><br />
<%@ Import Namespace="System.Data.OleDb" %><br />
<%@ Import Namespace="System.Web.Security" %><br />
<%@ Register TagPrefix="MySite" TagName="Login" Src="login.ascx" %><br />
<br />
<script language="C#" runat="server"><br />
private void Page_Load(Object sender, EventArgs E) <br />
{<br />
if ((Page.IsPostBack) && (Page.IsValid)) {<br />
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Membership.mdb";<br />
string strSQL = "SELECT userName, userPassword FROM Membership WHERE userName='" + MyLogin.UserId + "'";<br />
<br />
OleDbConnection myConn = new OleDbConnection(strDSN);<br />
OleDbCommand myCmd = new OleDbCommand(strSQL, myConn);<br />
OleDbDataReader dr = null;<br />
try {<br />
myConn.Open();<br />
dr = myCmd.ExecuteReader();<br />
<br />
if(dr.Read()) {<br />
if(dr.GetString(1).Trim() == MyLogin.Password.Trim()) <br />
{<br />
FormsAuthentication.RedirectFromLoginPage(MyLogin.UserId, false);<br />
}<br />
else<br />
Message.Text = "Login mislukt. Probeer opnieuw";<br />
}<br />
else<br />
{<br />
Message.Text = "Login mislukt. Probeer opnieuw";<br />
}<br />
}<br />
catch(Exception myException) {<br />
Response.Write("Oops. The error: " + myException.Message);<br />
}<br />
finally {<br />
myConn.Close();<br />
}<br />
}<br />
}<br />
</script><br />
<html><br />
<body><br />
<h3>Login</h3><br />
<form runat="server" ID="Form1"><br />
<asp:Label id="Message" runat="server" /><br />
<MySite:Login id="MyLogin" BackColor="#FFFFCC" runat="server"/><br />
</form><br />
</body><br />
</html>
Is it possible to work with a OleDbConnection to connect to a SQL database?
thanks in advance
|
|
|
|
|
daviperke wrote: Is it possible to work with a OleDbConnection to connect to a SQL database?
Yes it is, but it's not recommended.
Note that in your new code problems 2 and 4 still remain. To solve 2 use a parametrized query and SqlParamaters. To solve 4 in the finally block write:
if (dr != null) dr.Close(); Also I don't recommend writing out any exception info. Use user-friendly messages to hide technical details.
|
|
|
|
|
Error: Could not use ''; file already in use.
this is the error i get when i fill in something and press login
code:
<%@ Page Language="C#" %><br />
<%@ Import Namespace="System.Data" %><br />
<%@ Import Namespace="System.Data.OleDb" %><br />
<%@ Import Namespace="System.Web.Security" %><br />
<%@ Register TagPrefix="MySite" TagName="Login" Src="login.ascx" %><br />
<br />
<script language="C#" runat="server"><br />
<br />
private void Page_Load(Object sender, EventArgs E) <br />
{<br />
if (Page.IsPostBack)
{<br />
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\sql server 2005\\MSSQL.1\\MSSQL\\Data\\db.mdf";<br />
string strSQL = "SELECT emailadres, paswoord FROM tblPersoneelslid WHERE emailadres='" + MyLogin.UserId + "'";<br />
<br />
OleDbConnection myConn = new OleDbConnection(strDSN);<br />
OleDbCommand myCmd = new OleDbCommand(strSQL, myConn);<br />
OleDbDataReader dr = null;<br />
<br />
try<br />
{<br />
myConn.Open();<br />
dr = myCmd.ExecuteReader();<br />
<br />
if (dr.Read())<br />
{<br />
if (dr != null) dr.Close();<br />
{<br />
if (dr.GetString(1).Trim() == MyLogin.Password.Trim())<br />
{<br />
FormsAuthentication.RedirectFromLoginPage(MyLogin.UserId, false);<br />
}<br />
else<br />
{<br />
Message.Text = "Login mislukt. Probeer opnieuw";<br />
}<br />
}<br />
}<br />
else<br />
{<br />
Message.Text = "Login mislukt. Probeer opnieuw";<br />
}<br />
<br />
}<br />
catch (Exception myException)<br />
{<br />
Response.Write("Foutmelding: " + myException.Message);<br />
}<br />
finally<br />
{<br />
myConn.Close();<br />
}<br />
}<br />
}<br />
</script>
|
|
|
|
|
You can't connect to the database file itself, unless it is detached from SQL Server.
In my previous post I meant using OleDbConnection just like SqlConnection, that is connecting to the server.
|
|
|
|
|
hmmm, my knowledge about SQL server is very bad, how can you detached the file from SQL server?
|
|
|
|
|
Apart from the fact that you probably shouldn't do it this way - In Object Explorer right-click on the database and then select Tasks->Detach...
|
|
|
|
|
hmmmm, i found another article about login control:
http://support.microsoft.com/kb/Q301240[^]
when i do all this, i don't get any error, but i can't login :s nothing happens when i press logon.
What can be the problem of this?
|
|
|
|
|
This article contains some bad practises, for example storing password in plain text, not separating Data Access from business logic or not closing a SqlConnection properly (should be done in a finally block). I also don't understand why simple html controls with runat="server" are used, instead of just using server controls like Textbox or Button . Honestly I'm surprised this was published on a Microsfot site.
To get back to your problem - you didn't describe your problem well enough, so I have no idea what could be wrong. Are you using ASP.NET 1.1 or 2.0? If the latter is the case you might want to consider using the new Membership provider (Google for 'ASP.NET membership', and you'll find many resources about the subject).
|
|
|
|
|
ty for the help, this asp?net membership seems very usefull.
i'm trying to make a login control on a ASP.NET website and also a login control on a Winform, both in C#.
it's difficult for me, but i don't give up
|
|
|
|
|
|
ty for all the info !
my login control for my ASP website works !! I used the ASP.NET membership
|
|
|
|
|
hi friends
how to creat chat window in asp,c#.net
can u help me
regards
saravanan
|
|
|
|
|
you can use system.net and system.io to make chat window in c#
|
|
|
|
|
|
Hi Guys
I am looking for Video streaming component like YouTube which i can integerate in my web application for uploading and sharing videos, can anyone suggest me the resources or the component name with which i can achieve functionality related to video streaming.
Regards
GOurav Verma
Gourav
|
|
|
|
|
i have a situation in which i have to trace the user who have accessed the website!I have not set any option for it.
Does the IIS not automatically maitain this information?
Any other solution to get this information while i have not made configuration for this perpose?
Website is in ASP.net 2.0
|
|
|
|
|
|
Hi
strcmd = "Insert into CreateAccount values('" + txtUname.Text + "','" + txtPass.Text + "','" + txtCPass.Text + "','" + txtEmail.Text + "','" + txtSQuest.Text + "','" + txtSAns.Text + "',;for new line wht i have to write.
'" + ChkEnquiry.Text + "','" + ChkStock.Text + "' ,'" + ChkPayroll.Text + "' )";
I m saving data in CreateAccount table ,I want to save Checkbox 's values like checked or not means in table i want to save 0 or 1, & while saving i want to check condition Checkbox1.checked==true or not tell me how to write code for this.
Plz help me as soon as possible
CARE CAREER
|
|
|
|