P.Suresh Kumar

P.Suresh Kumar

  • NA
  • 55
  • 6.7k

Passing values from database to next page

Apr 7 2019 11:55 PM
new.aspx :
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="new.aspx.cs" Inherits="View_new" %>  
  2. <meta charset="UTF-8" />  
  3. <meta name="viewport" content="width=device-width, initial-scale=1.0" />  
  4. <meta http-equiv="X-UA-Compatible" content="ie=edge" />  
  5. <link rel="stylesheet" media="screen" href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css' />  
  6. <!-- jQuery library -->  
  7. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  
  8. <!-- Latest compiled JavaScript -->  
  9. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  
  10. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>  
  11. <link rel="stylesheet" href="new.css" />  
  12. <style type="text/css">  
  13. body {  
  14. background: -webkit-linear-gradient(left, #1143a6, #00c6ff);  
  15. }  
  16. </style>  
  17. <script type="text/javascript">  
  18. var LoginApp = angular.module('LoginApp', []);  
  19. LoginApp.controller('LoginController', ['$scope''$http''$window'function ($scope, $http, $window) {  
  20. $scope.submit = function () {  
  21. var UserData = { username: $scope.Username, password: $scope.Password}  
  22. $http.post('new.aspx/btnLogin_Click', UserData)  
  23. .success(function (data, status, headers, config) {  
  24. if (data.d != "") {  
  25. $scope.message = data.d;  
  26. else {  
  27. $window.location.href = 'success.aspx';  
  28. }  
  29. }).error(function (data, status, headers, config) {  
  30. $scope.message = data.d;  
  31. });  
  32. }  
  33. }]);  
  34. </script>  
  35. <form id="formID" runat="server">  
  36. <div ng-controller="LoginController">  
  37. <asp:hiddenfield id="hdnScreenHeight" runat="server" />  
  38. <asp:hiddenfield id="hdnScreenWidth" runat="server" />  
  39. <section class="container ">  
  40. <div class="main_cont register">  
  41. <div class="login-panel">  
  42. <h3 class="login-heading">Zetekcastings</h3>  
  43. <div class="row">  
  44. <div class="col-md-12 col-sm-12">  
  45. <div class="form-group">  
  46. <asp:textbox type="text" class="form-control" id="txtUserName" runat="server" ng-model="Username" name="Name" placeholder="Username" value="" autocomplete="off" required></asp:textbox>  
  47. </div>  
  48. <div class="form-group">  
  49. <asp:textbox type="password" class="form-control" id="txtPassword" runat="server" ng-model="Password" name="Password" placeholder="Password" value="" autocomplete="off" required></asp:textbox>  
  50. </div>  
  51. <div class="float-right">  
  52. <asp:button type="button" id="btnLogin" runat="server" onclick="btnLogin_Click" text="Login" class="btn btn-primary" value="Login"></asp:button>  
  53. </div>  
  54. </div>  
  55. </div>  
  56. </div>  
  57. </div>  
  58. </section>  
  59. </div>  
  60. </form>  
new.aspx.cs :
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Data;  
  8. using System.Data.SqlClient;  
  9. using System.Net;  
  10. using System.Globalization;  
  11. using System.IO;  
  12. public partial class View_new : System.Web.UI.Page  
  13. {  
  14. protected void Page_Load(object sender, EventArgs e)  
  15. {  
  16. //this.txtUserName.Text = Request.QueryString["username"];  
  17. }  
  18. protected void btnLogin_Click(object sender, EventArgs e)  
  19. {  
  20. //string filepath = Server.MapPath("~/PMCustom/images/") + "top-button.png";  
  21. //FileInfo file = new FileInfo(filepath);  
  22. //Response.ClearContent();  
  23. //Response.AddHeader("Content-Disposition", "attachment;filename=" + file.Name);  
  24. //Response.TransmitFile(file.FullName);  
  25. //Response.End();  
  26. SqlCommand lsCmd = new SqlCommand("SP_VALIDATE_LOGIH");  
  27. lsCmd.Parameters.AddWithValue("@USERNAME", txtUserName.Text);  
  28. lsCmd.Parameters.AddWithValue("@PASSWORD", txtPassword.Text);  
  29. DataTable dt = ConnCls.ret_dt_Cmd(lsCmd);  
  30. string strUserid = dt.Rows[0]["USERID"].ToString();;  
  31. //string strDataMode = dt.Rows[0]["DATAMODE"].ToString();  
  32. string strloggedInTime = System.DateTime.Now.ToString();  
  33. string strhostName = Dns.GetHostName();  
  34. string strIpAddress = Dns.GetHostByName(strhostName).AddressList[0].ToString();  
  35. if (strUserid != "0")  
  36. {  
  37. HttpCookie userid = new HttpCookie("userid");  
  38. userid.Value = strUserid;  
  39. Response.Cookies.Add(userid);  
  40. string doll = Request.Cookies["userid"].Value;  
  41. Response.Write(doll);  
  42. HttpCookie username = new HttpCookie("username");  
  43. username.Value = txtUserName.Text;  
  44. Response.Cookies.Add(username);  
  45. string roll = Request.Cookies["username"].Value;  
  46. Response.Write(roll);  
  47. //HttpCookie ipaddress = new HttpCookie("ipaddress");  
  48. //ipaddress.Value = Dns.GetHostByName(strhostName).AddressList[0].ToString();  
  49. //Response.Cookies.Add(ipaddress);  
  50. //int loginIdVal = insertLog(strUserid, strUserName);  
  51. //HttpCookie loginId = new HttpCookie("logInId");  
  52. //loginId.Value = loginIdVal.ToString();  
  53. //Response.Cookies.Add(loginId);  
  54. //HttpCookie dataMode = new HttpCookie("dataMode");  
  55. //dataMode.Value = strDataMode.ToString();  
  56. //Response.Cookies.Add(dataMode);  
  57. if (strUserid != "0")  
  58. {  
  59. Response.Redirect("~/home/accountshome.html");  
  60. }  
  61. }  
  62. }  
  63. public int insertLog(string pUserid, string pUsername)  
  64. {  
  65. System.Web.HttpBrowserCapabilities objHBC = Context.Request.Browser;  
  66. string userLanguage = CultureInfo.CurrentCulture.Name;  
  67. SqlCommand cmd = new SqlCommand("PM_INSERT_LOG");  
  68. cmd.Parameters.Add("@USERID", pUserid);  
  69. cmd.Parameters.Add("@USERNAME", pUsername);  
  70. cmd.Parameters.Add("@BROWSERNAME", objHBC.Browser);  
  71. cmd.Parameters.Add("@VERSION", objHBC.Version);  
  72. cmd.Parameters.Add("@SPIXELHEIGHT", hdnScreenHeight.Value);  
  73. cmd.Parameters.Add("@SPIXELWIDTH", hdnScreenWidth.Value);  
  74. cmd.Parameters.Add("@ISMOBILE", objHBC.IsMobileDevice.ToString());  
  75. cmd.Parameters.Add("@ISJAVASCRIPT", objHBC.JavaScript.ToString());  
  76. cmd.Parameters.Add("@BROWSERTYPE", objHBC.Type);  
  77. cmd.Parameters.Add("@MOBILEMODEL", objHBC.MobileDeviceModel.ToString());  
  78. cmd.Parameters.Add("@CLIENTDETAIL", Context.Request.UserAgent.ToString());  
  79. cmd.Parameters.Add("@ISTABLES", objHBC.Tables.ToString());  
  80. cmd.Parameters.Add("@ISCOOKIES", objHBC.Cookies.ToString());  
  81. cmd.Parameters.Add("@ISACTIVEX", objHBC.ActiveXControls.ToString());  
  82. cmd.Parameters.Add("@PLATFORM", objHBC.Platform);  
  83. cmd.Parameters.Add("@USERLANGUAGE", userLanguage);  
  84. DataTable dt = ConnCls.ret_dt_Cmd(cmd);  
  85. string returnVal = dt.Rows[0]["LOGINID"].ToString();  
  86. return Convert.ToInt32(returnVal);  
  87. }  
  88. }  
accountsHomehtml :
  1. <!DOCTYPE html>  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <title></title>  
  5. <!--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>  
  6. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular-cookies.js"></script>-->  
  7. <!--<link rel="stylesheet" href="new.css" />-->  
  8. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>  
  9. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-cookies.js"></script>  
  10. <!--<script type="text/javascript">  
  11. var app = angular.module("LoginApp", ['ngCookies'])  
  12. .controller("LoginController"function ($scope, $cookies) {  
  13. debugger;  
  14. $scope.getUsername = function () {  
  15. debugger;  
  16. //$window.alert($cookies.get("username"));  
  17. return $cookies.get("username");  
  18. }  
  19. $scope.getUserid = function () {  
  20. debugger;  
  21. return $cookies.get("userid");  
  22. }  
  23. });  
  24. </script>-->  
  25. </head>  
  26. <body ng-app="LoginApp" ng-controller="LoginController">  
  27. <div>  
  28. <h3>Login successful!</h3>  
  29. </div>  
  30. <div>  
  31. Username : <span id="lblUserName" class="hidden-xs">{{getUsername()}}</span><br />  
  32. User Id : <span id="lblUserId" class="hidden-xs">{{getUserid()}}</span>  
  33. </div>  
  34. </body>  
  35. </html>  
  36. newAjs.js :  
  37. var app = angular.module("LoginApp", ['ngCookies'])  
  38. .controller("LoginController"function ($scope, $cookies) {  
  39. $scope.getUsername = function () {  
  40. return $cookies.get("username");  
  41. }  
  42. $scope.getUserid = function () {  
  43. return $cookies.get("userid");  
  44. }  
  45. });  
I can display the values by checking it in the database in the same page, but I cannot pass it to the next page. I don't know what mistake I have done.

Answers (3)