|
Hi, this code can help.
This is code for 2.0 login control u replace login1.username by ur textboxcontrol.text
and by this code it will create cookie in ur local system and below code u place in ur pageload This will work fine....
CheckBox chkBox = (CheckBox)Login1.FindControl("RememberMe");
if (chkBox.Checked==true)
{
HttpCookie myCookie = new HttpCookie("myCookie"); //Instance the new cookie
Response.Cookies.Remove("myCookie"); //Remove previous cookie
Response.Cookies.Add(myCookie); //Create the new cookie
myCookie.Values.Add("user", this.Login1.UserName); //Add the username field to the cookie
DateTime deathDate = DateTime.Now.AddDays(1); //Days of life
Response.Cookies["myCookie"].Expires = deathDate; //Assign the life period
myCookie.Values.Add("pass", this.Login1.Password);
}
Getting after Cookie created
if (Request.Cookies["myCookie"] != null) //Cookie Exists??
{
HttpCookie cookie = Request.Cookies.Get("myCookie");
string user = cookie.Values["user"].ToString();
if (user != "")
{
Login1.UserName = user; //Write the username onto login username textbox
}
}
came out of hardwork
|
|
|
|
|
thanks for the code. But i have to know how to redirect to the page which comes after login page directly. when there is cookie available at page load event then how to redirect to the next page from the login page
|
|
|
|
|
Hi All,
I am trying Javascript for Validation of a new User Registration.
I want to know whether user already exits or not.
I m trying to check it on Submit button. I want to do it through Javascript.
I confused while mixing the code of javascript and ASp.net.
I created a string array of all user already exist.
now I want to check it in java script for new user's name.
I m new to javascript.
Please guideme thanks in advance,.
Asp:
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
con = new OleDbConnection();<br />
con.ConnectionString = conString;<br />
con.Open();<br />
<br />
cmdSelect = new OleDbCommand("select * from User_Information", con);<br />
da = new OleDbDataAdapter("select * from User_Information",con);<br />
ds = new DataSet();<br />
da.Fill(ds);<br />
ArrayPassword = new string[100];<br />
ArrayNames = new string[100];<br />
for (i= 0; i < ds.Tables[0].Rows.Count;i++ )<br />
{<br />
ArrayNames[i]=(ds.Tables[0].Rows[i].ItemArray[0].ToString());<br />
ArrayPassword[i]=(ds.Tables[0].Rows[i].ItemArray[1].ToString());<br />
}<br />
int j = ArrayNames.Count;<br />
string arr = ArrayNames;<br />
}
Javascript:
function Validate()<br />
{<br />
for (var i=0;i<document.forms[0].elements.length; i++) <br />
{ <br />
var val=document.forms[0].elements[i].value; <br />
if(val=="")<br />
{<br />
alert("Please Enter the "+document.forms[0].elements[i].name+ " !");<br />
document.forms[0].elements[i].focus();<br />
return false;<br />
} <br />
}<br />
document.forms[0].action="Default3.aspx";<br />
var User_name=document.forms[0].elements["Name"].value;<br />
var User_password=document.forms[0].elements["Password"].value;<br />
var i=<%=i%>;<br />
var j; <br />
var arrayNames=<%=ArrayNames%> ;
for(j=0;j<i;j++)<br />
{<br />
if(User_name==arrayNames[j])<br />
alert("User Exists");<br />
else<br />
alert("User not Exists");<br />
}<br />
<br />
<br />
}
-- modified at 7:54 Tuesday 19th June, 2007
-- modified at 8:29 Tuesday 19th June, 2007
Bajrang Singh
Using .net 2.0 (VS2005)
|
|
|
|
|
Personally I think that it will be a bad idea to use javascript for validations such as user and password. If you really want to use flashy stuff for validation, use Ajax.
|
|
|
|
|
for starters you can learn Ajax from www.w3schools.com. But for Ajax you need to have knowledge of Javascript, XML.
|
|
|
|
|
This is a disaster. You should never assume that ANYTHING on the client side is what you expect, anything you do in client side, should be validated on the server. It's trivial to hack your page, and make it accept any password you like. It's also trivial to view the source, and see all the username/passwords in your system. Even allowing SQL that returns all the user details is a mess and should be avoided. Please tell me you're just playing around, and no-one will ever rely on this code for security ?
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 )
|
|
|
|
|
Thanks Christian Graus for advice.
I was just playing around.
I will be highly thankful to you if you can tell me what the Mistake is there in following line
var arrayNames=<%=ArrayNames%> ; // ERROR COMES IN THIS LINE ,,,
Thanks again.
Bajrang Singh
Using .net 2.0 (VS2005)
|
|
|
|
|
How to deploy our application in three Machines in splitted environment like below ?
1 Machine - ASPX pages with Code behind as a dll (Presentation Tier)
2 Machine - COM+ dll (Business Tier)
3 MAchine - SQL Server (DataBase Tier)
Regards,
Sylvester G
sylvester_g_m@yahoo.com
|
|
|
|
|
Hello Developers
Anyone here implemented Google Base API??? Or anyOne knows about some ASP>.net control to implement this in a better way?? Thanks for ur time
|
|
|
|
|
hi friens
i wrote the code in codebehind to check avilability username from database(it is work fine).
but page has CAPTCHAImage concept.if i click that check avilability button
the page refreshed the CAPTCHAImage refreshed.
how can i reduce the refershment of CAPTCHAImage
i try AJAX also.i use AJAX my entire functionality should change
i used ispastpack also not suitable
can anyone help me
regards
saravanan
|
|
|
|
|
|
In the aspx page, in page directive section use the smartNavigation =true, this will handle the refreshment of page, it will support IE5.5 or above
Regards
MAHESH
|
|
|
|
|
Hi.
I need to cache a usercontrol on a page.
I have tried:
<%@ OutputCache Duration = "100" VaryByParam="none" %> in the design of the UC.
And it gives the OBJECT NOT SET TO AN INSTANCE... error on the container page when i try to reference the UC.
I have also tried:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(100));<br />
Response.Cache.SetCacheability(HttpCacheability.Public);
in the page load of the usercontrol.
In the container page code i try:
if (UCarticles1.CachePolicy.SupportsCaching)<br />
{<br />
UCarticles1.CachePolicy.Duration = new TimeSpan(0,0,20);<br />
}
But I get the value of false from the if statement.
Can someone help me please? What am I doing wrong?
Thanks for your help.
|
|
|
|
|
Hi,
Caching in UserControls is called Fragment Caching.
When u use Fragment Caching you can not perform any operation with the instance of that usercontrol in the container page's codebehind. and if u try to do so u will get NullReferenceException.
I hope this will help you.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Thanks for that. Can you give some sort of example?
Thanks
|
|
|
|
|
Hi,
Your usercontrol itself is an example.
You just remove caching feature from your user control and then try to run you application.
I m sure u wont get exception at that time.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
I NEED caching to run my app., hence I cannot remove the caching feature.
I want the contents of the UC to be cached for 2 minutes and then afterwards, get the updated contents and display on container page and then cached again...
Thanks
|
|
|
|
|
Hi,
If its neccessary to user Caching in ur usercontrol then you should choose some other approach to implement the functionality that u want to implement by using reference of UC in the page codebehind.
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
Thanks.
I'll see what I can come up with.
|
|
|
|
|
Add the following element to the OutputCache directive for your usercontrol
VaryByControl= name of the property by which u want to cache your control
|
|
|
|
|
Hello to Everyone,
How can we use multiline and New line character in asp.net(vb)
Thank You.
|
|
|
|
|
Well hemant im unsure but I think "vbCrLf" can be used for newline.
|
|
|
|
|
Hi, I finally got my code to send a user's username and password to the database. However, it did not check to see if the username has already been taken and did not prompt the user for a new username like it was designed to. I will put in code to prevent sql injection and use other validations later. As for now I just want it to work. Please help point out the cause of this problem. Thank you in advance for your help
Private Sub lblRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblRegister.Click
Dim myConnection As OdbcConnection
Dim myCommand As OdbcCommand
Dim strInsert As String
Dim strSQL As String
strSQL = String.Empty
myConnection = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=myServer;Database=myDB;User=myUser; Password=myPW;Option=3;")
strSQL = String.Format("SELECT UserName FROM myTable WHERE (UserName='{0}');", txtUserName.Text)
myCommand = New OdbcCommand(strSQL, myConnection)
myCommand.CommandType = CommandType.Text
myConnection.Open()
Dim result As Integer = myCommand.ExecuteNonQuery()
If result > 0 Then
lblMessage.Text = "That user name is already taken!"
lblMessage.Text &= " Please choose another user name."
Else
strInsert = "INSERT into myTable (FirstName,LastName,Password,UserName)values (?,?,?,?)"
Dim myCommand1 As OdbcCommand = New OdbcCommand(strInsert, myConnection)
myCommand1.CommandType = CommandType.Text
myCommand1.Parameters.Add("@FirstName", txtFirst.Text)
myCommand1.Parameters.Add("@LastName", txtLast.Text)
myCommand1.Parameters.Add("@Password", txtPassword.Text)
myCommand1.Parameters.Add("@UserName", txtUserName.Text)
Dim result1 As Integer = myCommand1.ExecuteNonQuery()
myConnection.Close()
End If
txtFirst.Text = ""
txtLast.Text = ""
txtUserName.Text = ""
txtPassword.Text = ""
End Sub
|
|
|
|
|
Hi,
In which context your code doesnt work?
Do u get any error or exception? if yes then at which line?
Thanks and Regards,
Chetan Ranpariya
|
|
|
|
|
The code ran without any error messages and it sends the user's info such as username, password, etc to the database for storage. However, to my surprise when I check to see if it had checked for duplicate username when someone registers, it did not do so. The select statement was supposed to count the number of row in which UserName'{0}' = txtUserName.text. If the row count is greater than 0 then the username is already in use and an error message was supposed to fire. I don't know if that is the problem, it looks fine to me though. Please take a close look at the code, perhaps you'll find something I overlooked. Thank you again for your help.
|
|
|
|