trying to do something super cool on my web site [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
how to do that if user did not did anything on the website for a set amount of time the website will log out him?
is it from the c# page?
how can i tocount the time sincethe last touch on something?
and how can i alert it?
plss help
i want to add it here:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Conect"]!=null)
{
if (!(bool)Session["Conect"])
{
Response.Redirect("Must-Had.aspx", true);
}
}
else
Response.Redirect("Must-Had.aspx", true);
if (Session["val"]!=null)
{
if ((bool)Session["val"])
{
limission4.Visible = true;
mission4.InnerText =(string)Session["tit"];
}
}
if (Session["val2"] != null)
{
if ((bool)Session["val2"])
{
limission5.Visible = true;
mission5.InnerText = (string)Session["tit2"];
}
}
}

Place this somewhere between the <body> and </body> tags.
<script type="text/javascript">
var timeoutHandle = window.setTimeout("window.close();", 3000);
window.onscroll = function (e) {
window.clearTimeout(timeoutHandle);
timeoutHandle = window.setTimeout("window.close();", 3000);
}
</script>
You can change the "3000" to whatever amount of time you want the page to last.
You can also change the "window.close();" to whatever you want the page to do when the time runs out. The "window.close();" command will just close the page.

Related

For cycle always give same output [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
1. Summarize the problem
The following for cycle keeps on running as i want, but always give me the same clicked button that is "0".
It does not give me an error. But by playing the game i can see that it's always the same number.
2. Describe what you've tried
I've tried searching around the internet for people like me. but sadly i couldn't find anything.
3. Show some code
Code that i'm talking about.
int ButtonNum;
public void Start()
{
for (int i = 0; i < ButtonsPage.Length; i++)
{
ButtonsPage[i].GetComponent<Button>().onClick.AddListener(delegate { ButtonClicked(ButtonNum); });
}
}
public void ButtonClicked(int i)
{
Debug.Log("Clicked" + i);
if (WhichType == "Nose")
{
NoseColor.sprite = NosesColor[i];
NoseOutline.sprite = NosesOutline[i];
}
//ButtonNum will be used to say which one is clicked. Still haven't add it though cause i wanted to fix this problem before
}
You are not modifying ButtonNum in any way, I assume the goal is to use i as button number, try changing your code to:
public void Start()
{
for (int i = 0; i < ButtonsPage.Length; i++)
{
var temp = i;
ButtonsPage[i].GetComponent<Button>().onClick.AddListener(delegate { ButtonClicked(temp); });
}
}
Temporary variable is required due to how closures work in C#.

C# time.sleep not working as expected for no apparent reason [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
So this algorithm should flash the word finished in 1 second intervals 3 times but it just freezes for 5 seconds instead. Any ideas?
bool appear = false;
int i = 0;
while (i < 5)
{
i++;
if (appear == false)
{
appear = true;
Finished_label.Visible = true;
}
else
{
appear = false;
Finished_label.Visible = false;
}
System.Threading.Thread.Sleep(1000);
}
*Edit I am writing this in C# Visual Studio Windows Forms Application
Thread.Sleep() blocks the UI thread, so you don't see the changes. You could use
await Task.Delay(1000);

Can't add anything in my DB C# using ADO Entity [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm a beginner on Visual Studio so, please, be gentle :)
Here the code i'm using :
private void button1_Click(object sender, EventArgs e)
{
using (KrqcSDBEntities context = new KrqcSDBEntities())
{
activite monActivite = new activite();
monActivite.lieu_activite = "Paris";
monActivite.nom_activite = "Natation";
context.activite.AddObject(monActivite);
activite test = context.activite.FirstOrDefault(o => o.id == 1);
context.SaveChanges();
}
}
I succesfully succeed to get value from my DB but i can't add anything in it without any error.
Can you please have a look on it and try to help me ?
It would be very nice !
Thanks you
SaveChanges first, then get the item from data store:
private void button1_Click(object sender, EventArgs e)
{
using (KrqcSDBEntities context = new KrqcSDBEntities())
{
activite monActivite = new activite();
monActivite.lieu_activite = "Paris";
monActivite.nom_activite = "Natation";
context.activite.AddObject(monActivite);
context.SaveChanges();
activite test = context.activite.FirstOrDefault(o => o.id == 1);
}
}

Right Approach to Make cart in asp.net [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm making a shopping cart in asp.net with c# using DataTable stored in Session and all items stored in DataTable.
public DataTable dtCart = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["dtCart"] == null) { CreateCartTable(); }
}
}
protected void CreateCartTable()
{
dtCart.Rows.Clear();
dtCart.Columns.Clear();
dtCart.Columns.Add(new DataColumn("Prd_Id", Type.GetType("System.String")));
dtCart.Columns.Add(new DataColumn("Prd_Name", Type.GetType("System.String")));
dtCart.Columns.Add(new DataColumn("Prd_Img", Type.GetType("System.String")));
dtCart.Columns.Add(new DataColumn("Qty", Type.GetType("System.Int32")));
dtCart.Columns.Add(new DataColumn("Rate", Type.GetType("System.Decimal")));
dtCart.Columns.Add(new DataColumn("Amount", Type.GetType("System.Decimal")));
dtCart.Columns.Add(new DataColumn("TotalAmount", Type.GetType("System.Decimal")));
Session["dtCart"] = dtCart;
}
Is this right approach or any other way is more elegant and light on application?
FYI I'm using web forms.
You can make a class to cart:
public class Cart
{
public string Prd_Id{set;get;}
public string Prd_Name{set;get;}
//and so on...
}
then in page:
Cart obj=new Cart{Prd_Id="1",Prd_Name="John"};
Session["dtCart"]=obj;

asp filter ajax and usual request [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have asp webpage in Net4.0. In this version I can't use async method. I have ajax container:UpdatePanel . I have button in this panel. When I press button the page doesn't reload and in debug mode I see Page load method. I need filter ajax request and usual. How can I this do?
Like this:
protected void Page_Load(object sender, EventArgs e)
{
if(request.isAsync)
{
//this is ajax
}else
{
//this is usual request.
}
}
You can use extension method from here
public static bool IsAjaxRequest(this HttpRequest request)
{
if (request == null)
{
throw new ArgumentNullException("request");
}
return (request["X-Requested-With"] == "XMLHttpRequest") || ((request.Headers != null) && (request.Headers["X-Requested-With"] == "XMLHttpRequest"));
}
and make it:
if(request.IsAjaxRequest())

Categories