how should I disable the right click in Popup Window. I dont want the user to save or print the document in the Popup Window. Here is my interface Interface
Here is my aspx.cs code under TreeView1_SelectedNodeChanged
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
if (Session["loggedUserID"] == null && Session["loggedRoleID"] == null)
{
Response.Redirect("~/Login.aspx");
}
else
{
if (TreeView1.SelectedNode.Parent == null)
{
ltEmbed.Visible = false;
}
else
{
ltEmbed.Visible = true;
string Text = TreeView1.SelectedNode.Text.ToString();
int loggedUserID = Convert.ToInt32(Session["loggedUserID"]);
List<BOL.UserInfo> userslist = new UserInfos().List();
BOL.UserInfo loggeduser = userslist.Where(x => x.UserID == loggedUserID).FirstOrDefault();
BOL.DMS getdetail = new DMSS().GET_FILE(loggeduser.SUBSIDIARY_CD, Text);
string FILE_NAME = getdetail.F_NAME;
string FILE_PATH = getdetail.MAIN;
string url = String.Format(ResolveUrl(FILE_PATH));
string script = "window.open('" + url + "', '_blank','popup_window','width=700,height=600,left=100,top=100,resizable=false,oncontextmenu= return false');";
ClientScript.RegisterStartupScript(this.GetType(), "popUp", script, true);
}
}
}
Thank you.
Related
I'm trying with some code to disable/enable button based on user permission.
However, the code seem like nothing change to the system.
Anyone can advice/guide me on these? Thanks in advance.
public partial class frmTest : Form
{
public string UserID;}
private void frmTest_Load(object sender, EventArgs e)
{
RefreshActivate();
private void RefreshActivate()
{
DataSet ds = new DataSet();
MySQLClass.query(ds, "SELECT * FROM users WHERE username = '" + UserID + "'");
string strPermission = ds.Tables[0].Columns["permission"].ToString();
if (strPermission == "Admin")
{
btnActivate.Enabled = true;
}
else if (strPermission == "ReadOnly")
{
btnActivate.Enabled = false;
}
else
{
btnActivate.Enabled = false;
}
}}
Picture: https://i.stack.imgur.com/BevH8.png
Try to check first the permission if not null
if(!strPermission.Equals(null)//or ""
{
if (strPermission == "Admin")
{
btnActivate.Enabled = true;
}
else if (strPermission == "ReadOnly")
{
btnActivate.Enabled = false;
}
}else{
//value of permision is empty
MessageBox.Show("Permission is empty");
}
Now if the permission is empty it is something to do or fix when retrieving the data
Hey I was trying to create a method like...
private void btnSubmit_Click(object sender, EventArgs e)
{
FillIn();
}
private void FillIn()
{
if (txtName.Text == "")
{
txtName.Text = "Bob Frank";
}
if (txtAddress.Text == "")
{
txtAddress.Text = "4111 N Pensyvania Ave.";
}
if (txtCity.Text == "")
{
txtCity.Text = "Longbeach";
}
if (txtState.Text == "")
{
txtState.Text = "CA";
}
if(txtZip.Text == "")
{
txtZip = "90210";
}
}
this code works great but when I try to add parameters to it like this..
private void btnSubmit_Click(object sender, EventArgs e)
{
FillIn(txtName.Text, txtStreetAddress.Text, txtCity.Text, txtState.Text, txtZip.Text);
}
private void FillIn(string name, string address, string city, string state, string zip)
{
if (name == "")
{
name = "Bob Frank";
}
if (address == "")
{
address = "4111 N Pensyvania Ave.";
}
if (city == "")
{
city = "Longbeach";
}
if (state == "")
{
state = "CA";
}
if(zip == "")
{
zip = "99210";
}
}
it stops working and the text boxes won't fill back in and won't error out, how can I fix this?
You need to pass the actual controls. If you try and pass txtName.Text it just reads the value in the property and you can't update it.
private void btnSubmit_Click(object sender, EventArgs e)
{
FillIn(txtName, txtStreetAddress, txtCity, txtState, txtZip);
}
private void FillIn(TextBox name, TextBox address, TextBox city, TextBox state, TextBox zip)
{
if (name.Text == "")
{
name.Text = "Bob Frank";
}
if (address.Text == "")
{
address.Text = "4111 N Pensyvania Ave.";
}
if (city.Text == "")
{
city.Text = "Longbeach";
}
if (state.Text == "")
{
state.Text = "CA";
}
if(zip.Text == "")
{
zip.Text = "99210";
}
}
Here's my requirement. There is a public website which takes alphanumeric string as input and Retrieves data into a table element (via button click). The table element has couple of labels which gets populated with corresponding data. I need a tool/solution which can check if a particular string exists in the website's database. If so retrieve all the Ids of all the occurrences of that string. Looking at the "view source" of the website (No JavaScript used there), I noted the input element name and the button element name and with the help of existing samples I was able to get a working solution. Below is the code which works but I want to check if there is any better and faster approach. I know the below code has some issues like "infinite loop" issue and others. But I am basically looking at alternate solution which can work quickly for a million records.
namespace SearchWebSite
{
public partial class Form1 : Form
{
bool searched = false;
long i;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
i = 1;
WebBrowser browser = new WebBrowser();
string target = "http://www.SomePublicWebsite.com";
browser.Navigate(target);
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(XYZ);
}
private void XYZ(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser b = null;
if (searched == false)
{
b = (WebBrowser)sender;
b.Document.GetElementById("txtId").InnerText = "M" + i.ToString();
b.Document.GetElementById("btnSearch").InvokeMember("click");
searched = true;
}
if (b.ReadyState == WebBrowserReadyState.Complete)
{
if (b.Document.GetElementById("lblName") != null)
{
string IdNo = "M" + i.ToString();
string DateString = b.Document.GetElementById("lblDate").InnerHtml;
string NameString = b.Document.GetElementById("lblName").InnerHtml;
if (NameString != null && (NameString.Contains("XXXX") || NameString.Contains("xxxx")))
{
using (StreamWriter w = File.AppendText("log.txt"))
{
w.WriteLine("Id {0}, Date {1}, Name {2}", IdNo, DateString, NameString);
i = i + 1;
searched = false;
}
}
else
{
i = i + 1;
searched = false;
}
}
else
{
i = i + 1;
searched = false;
}
}
}
}
}
If the page after seach button clicked contains txtId and btnSearch controls than you can use this code snippet, this is not faster but the correct form I think.
public partial class Form1 : Form
{
bool searched = false;
long i = 1;
private string IdNo { get { return "M" + i.ToString(); } }
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
i = 1;
WebBrowser browser = new WebBrowser();
string target = "http://www.SomePublicWebsite.com";
browser.Navigate(target);
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(XYZ);
}
private void XYZ(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser b = (WebBrowser)sender;
if (b.ReadyState == WebBrowserReadyState. Complete)
{
if (searched == false)
{
DoSearch(b); return;
}
if (b.Document.GetElementById("lblName") != null)
{
string DateString = b.Document.GetElementById("lblDate").InnerHtml;
string NameString = b.Document.GetElementById("lblName").InnerHtml;
if (NameString != null && (NameString.Contains("XXXX") || NameString.Contains("xxxx")))
using (StreamWriter w = File.AppendText("log.txt"))
w.WriteLine("Id {0}, Date {1}, Name {2}", IdNo, DateString, NameString);
}
i++;
DoSearch(b);
}
}
private void DoSearch(WebBrowser wb)
{
wb.Document.GetElementById("txtId").InnerText = IdNo;
wb.Document.GetElementById("btnSearch").InvokeMember("click");
searched = true;
}
}
Hello im learning c# at the moment and wish to If a statement is true then redirect to another ASpage so far with no luck.
My attempt is below, what the code does is check the text boxes to see if they have a value and if they do then it will save that record in the database as a new user.The code works its just the redirect at the end that isn't working.
Any help would be great
protected void Button2_Click(object sender, EventArgs e)
{
if (!String.IsNullOrWhiteSpace(txtTitle.Text))
{
user.Title = txtTitle.Text;
}
if (!String.IsNullOrWhiteSpace(txtFirstName.Text))
{
user.Forename = txtFirstName.Text;
}
if (!String.IsNullOrWhiteSpace(txtSurname.Text))
{
user.Surname = txtSurname.Text;
}
if (!String.IsNullOrWhiteSpace(txtUsername.Text))
{
user.Username = txtUsername.Text;
}
// call save function at end of statements
if (!String.IsNullOrWhiteSpace(txtAddress.Text))
{
user.Address1 = txtAddress.Text;
}
if (!String.IsNullOrWhiteSpace(txtAddress2.Text))
{
user.Address2 = txtAddress.Text;
}
if (!String.IsNullOrWhiteSpace(txtPostcode.Text))
{
user.PostCode = txtPostcode.Text;
}
if (!String.IsNullOrWhiteSpace(txtCode.Text))
{
user.CountryCode = txtCode.Text;
}
if (!String.IsNullOrWhiteSpace(txtEmail.Text))
{
user.Email = txtEmail.Text;
}
//if (!string.IsNullOrWhiteSpace(txtDate.Text))
//{
// DateTime _entrydate;
// if (DateTime.TryParse(txtDate.Text, out _entrydate))
// {
// user.EntryDate = _entrydate;
// }
//}
user.CompanyID = AppSession.Company.ID;
user.Status = 1;
user.PasswordHash = "test";
user.EntryDate = DateTime.Now;
user.UpdateDate = DateTime.Now;
user.Deleted = false;
bool result = userDao.SaveNewUser(user);
if (result == true)
{
Response.Redirect("User/List/");
}
}
}
}
You need to Redirect to another ASPX page, not a directory.
Something like
Response.Redirect("User/List/UserList.aspx");
Private static string CheckValues(TextBox t)
{
if(!string.IsnullOrEmpty(t.Text.Trim())
{
return t.Text;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
user.Title =CheckValues(txtTitle.Text);
user.Forename = CheckValues(txtFirstName.Text);
user.Surname = CheckValues(txtSurname.Text);
user.Username = CheckValues(txtUsername.Text);
user.Address1 = CheckValues(txtAddress.Text);
user.Address2 = CheckValues(txtAddress.Text);
user.PostCode = CheckValues(txtPostcode.Text);
user.CountryCode = CheckValues(txtCode.Text);
user.Email = CheckValues(txtEmail.Text);
if(CheckValues(txtDate.Text))
{
DateTime _entrydate;
if (DateTime.TryParse(txtDate.Text, out _entrydate))
{
user.EntryDate = _entrydate;
}
}
bool result = userDao.SaveNewUser(user);
if (result)
{
Response.Redirect("~/User/List/somepage"); //~ for root directory , if there is any page use that or use the exact url here.
}
}
Kindly note the above url format will only work if you have URL Rewriting/Routing in your app
I am having a problem. I am new in c#. In this code when I click the button2, it will run bgutures.RunWorkerAsync(); only. But I need to modify it such like if I click on button2, all items the checkedListBox1.allitems contains are download, one by one in bgworker. Can anyone please help in this.
My code is :
private void button2_Click(object sender, EventArgs e)
{
button2.Enabled = false;
string DayAtoZ = " ";
string DayDead = " ";
string Dayutures = " ";
string Daysify = " ";
string Dayfx = " ";
if (checkedListBox1.SelectedItem == "")
{
}
else if (checkedListBox1.SelectedItem == Dayutures)
{
}
else if (checkedListBox1.SelectedItem == DayAtoZ)
{
}
else if (checkedListBox1.SelectedItem == Daysify)
{
}
else if (checkedListBox1.SelectedItem == DayDead)
{
}
else if (checkedListBox1.SelectedItem == Dayfx)
{
}
{
bgutures.RunWorkerAsync();
}
{
bgDead.RunWorkerAsync();
}
{
bgsify.RunWorkerAsync();
}
{
bgAtoZ.RunWorkerAsync();
}
{
}
}
Instead of one BackgoundWorker use as many as your need.
if (checkedListBox1.SelectedItem == "")
{
var worker = new BackgroundWorker();
.. do setup
worker.RunWorkerAsync();
}
else if (checkedListBox1.SelectedItem == Dayutures)
{
var worker = new BackgroundWorker();
.. do setup
worker.RunWorkerAsync();
}