Does Page.ClientScript available been used in class.cs? - c#

I have a class.cs file as following, but there is an error for my "Page.ClientScript", which said "an object reference is required for the non-static field, method, or property 'System.Web.UI.Page.ClientScript.get'". So I. wonder is the page.clientscript is not available to used in class.cs? Any other method to use instead of page.clientscript ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.Data;
using System.Web.Script.Services;
public class SessionExpired
{
public SessionExpired()
{
string csname = "timeoutWarning";
Type cstype = this.GetType();
if (!Page.ClientScript.IsStartupScriptRegistered(cstype, csname))
{
string strconfirm = "<script>" +
"window.setTimeout('SessionTimeOutHandler()', 60000);" +
"function SessionTimeOutHandler() { " +
"alert('Your login session is expired');" +
"window.location='../Processing.aspx';" +
"}</script>";
Page.ClientScript.RegisterStartupScript(cstype, csname, strconfirm, false);
}
}
}

You are having problems because it looks like you are using a class which doesn't derive from System.Web.UI.Page. However, as long as you have access to HttpContext, you can just say:
using System.Web;
using System.Web.UI;
...
var page = HttpContext.Current.CurrentHandler as Page;
if( page == null ){
// throw an exception, something bad happened
}
// now you have access to the current page...
page.ClientScript.RegisterStartupScript();

Related

UI TestStack White Get Value from a DataCell

Does anyone know how to get Vlaue from a ""DataCell(DataGridViewTextBoxCell)"?
I need to get a value from DataCell using its "Name" = "Symbol Row 0" or "RuntimeId" = "42 1966418 3 1 0"".
My current code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestStack.White;
using TestStack.White.Factory;
using TestStack.White.UIItems;
using TestStack.White.UIItems.Finders;
using TestStack.White.UIItems.WindowItems;
namespace UI_006
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(System.Diagnostics.Process.GetProcessesByName("program1")[0].Id);
Application application = TestStack.White.Application.Attach(System.Diagnostics.Process.GetProcessesByName("program1")[0].Id);
Window Calcwindow = application.GetWindow(SearchCriteria.ByText("toto"), InitializeOption.NoCache);
application.WaitWhileBusy();
}
}
}
My UISpy SceenShot:

I am trying to save data in cookie but facing issue in the code as it is underlined by a red line

This is my code in registation.aspx
string loginid=loginId;
string passwrd= password;
int verified= Verified;
int idType = IdType;
string username= UserName;
DateTime dateCreated = DateTime.Now;
tbl_user_login objUser = new tbl_user_login();
result=objUser.registerUser(loginid, passwrd, verified, idType, username, dateCreated);
HttpCookie cook = Request.Cookie("UserLoginId");
if (cook != null)
{
//show the user login id here
}
This is the code of the class tbl_ser_login file
HttpCookie myCookie = new HttpCookie("UserLoginId");
myCookie["loginid"] = result.ToString();
Response.Cookie.Add(myCookie);
In both of them the Response is showing red underlined and also it is showing as 'Response" does not exist in the current context.
These Libraries are included in class
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Linq;
using System.Web.UI.WebControls;

Why "threading" is unknown for visual studio?

I include using System.Windows; but threading still it doesn't exist in the namespace
?!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Net.Mail;
using System.Net;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows;
using System.Timers;
using Graduation_Project;
namespace GP
{
public partial class Register : System.Web.UI.Page
{
static int count = 0;
static int timer = 600;
protected void Page_Load(object sender, EventArgs e)
{
System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
dt.Interval = new TimeSpan(0, 0, 0, 0, 600000); // 600000 Milliseconds
dt.Tick += new EventHandler(dt_Tick);
}
still have aproblem
System.Windows.Threading.DispatcherTimer is in WindowsBase.dll assembly. Make sure you have added reference to that assembly.
MSDN -
UPDATE -
DispatcherTimer is meant for WPF and Silverlight apps. It can't be used for asp.net project. Instead you should use Timer class meant for web projects.
DispatcherTimer class belongs on System.Windows.Threading namespace which it's belongs in WindowsBase.dll
Be sure you added the right assembly in your project. It is proably in C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0 folder..

How to get grid items --wpf

I made WPF application named as WpfApplication7.It has several folders. One of them is named as Assign_Rights . I have created a UserControl in this folder and named it as Assignment_Rights. Inside this user control i have created a grid and bind it to data explicitly! Now There is button name as Click New. It shows me that PK(Primary Key-Value) of a selected item from grid.
User n = grid.GetRow(view.FocusedRowHandle) as User;
int abc = n.Primary_Key;
Question: As i wrote code to get PK of Selected item it generated error at
int abc = n.Primary_Key;
by saying
Error 'WpfApplication7.Assign_Rights.User' does not contain a definition for 'Primary_Key' and no extension method 'Primary_Key' accepting a first argument of type 'WpfApplication7.Assign_Rights.User' could be found (are you missing a using directive or an assembly reference?) D:\Backup_WPFAppliacation7\New folder\WpfApplication7\WpfApplication7\Assign_Rights\Assignment_Rights.xaml.cs 59 28 WpfApplication7
How to Solve this Error?
EDIT
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Grid;
namespace WpfApplication7.Assign_Rights
{
public partial class Assignment_Rights : UserControl
{
int useridd;
nrcsaEntities d = new nrcsaEntities();
public Assignment_Rights()
{
InitializeComponent();
}
private void ToggleButton1_Click_1(object sender, RoutedEventArgs e)
{
if (view.IsRowSelected(view.FocusedRowHandle) == false)
{
DXMessageBox.Show("Please Select any Item From Grid List");
}
else
{
User n = grid.GetRow(view.FocusedRowHandle) as User;
int abc = n.Primary_Key;
var getd = from p in d.Users select p;
MessageBox.Show(view.FocusedRowHandle.ToString());
} . . . .

using Microsoft Translate ( GetTranslation Service )

I'm going to build website that uses the translation service from Microsoft. I need to get all the available translations for each word but the code I have provides only one translation while it is supposed to give all available translations. Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using microsofttranslator;
using System.Text;
using System.Net;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.ServiceModel.Channels;
using System.ServiceModel;
using TranslatorService;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{string Appid="my Appid";
string t="any text";
microsofttranslator.TranslateOptions options = new microsofttranslator.TranslateOptions();
options.Category = "general";
options.ContentType = "text/plain";
options.User = "TestUserId";
options.Uri = "";
bool a=true;
SoapService s = new SoapService();
microsofttranslator.GetTranslationsResponse translations = s.GetTranslations(Appid, t, "ar", "en", 5,a, options);
Response.Write(string.Format("Available translations for source text '{0}' are", t));
foreach (microsofttranslator.TranslationMatch translationMatch in translations.Translations)
{
Response.Write(string.Format("Translated text: {0}" + Environment.NewLine + " Rating:{1}" + Environment.NewLine + "Count:{2}" + Environment.NewLine, translationMatch.TranslatedText, translationMatch.Rating.ToString(), translationMatch.Count.ToString()));
} }}
I added Microsft translate WSDL as a web reference http://api.microsofttranslator.com/v2/Soap.svc?wsdl and I added TranslatorService as a service reference http://api.microsofttranslator.com/V2/Soap.svc
This code works well but as I said it gives only one translation while it is supposed to give all the available translations of a word. I cannot figure out what I am doing wrong.
Maybe you should use the "translateArray" method.
http://msdn.microsoft.com/en-us/library/ff512438.aspx

Categories