|
Well you can do:
this.Response.Redirect(name of web page / file to download etc)
or
this.Server.Transfer(url or whatever - will not work when linking to a file for downloading etc.)
The first one is better, but with the second, it doesnt change the url in the address bar on the browser so if you wanted to keep the full url a secret...
|
|
|
|
|
Thank you!
this.Response.Redirect(name of web page) works well, but I need it to open in its own window.
I think my prasing was incorrect...
|
|
|
|
|
Well, i asked that a short while back as well, you'll have to use a html button and in the onclick bit put:
window.open("website url","one_word_id_type_thing","resizable=0,width=550,height=400")
resizable=0 means you cant resize it 1 means that you can.
Just thought, to open a page in a new window, and keep the web forms button, add:
using System.Diagnostics;
then in the button put:
Process.Start("website url");
that should open it in a new window.
|
|
|
|
|
Hi.. I would like to ask about C# web application.I have created a calendar. I would like to ask that if i click the date on the calendar,how can i retrieve the database ?? I have tried butit seem like is not working. Below is the code, could anyone help me with it as i'm totally lost?? Thanks!! The code:
private void Radcalendar2_SelectionChanged(object sender, System.EventArgs e)
{
TBDate1.Text = CAL1.SelectedDate.ToLongDateString();
SqlConnection conn=new SqlConnection("my connection string");
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Particulars WHERE DateField = @Date";
cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = DateTime.Parse(TBDate1.Text);
}
I just want to retrieve(view) the user's login/logout time of date we have click on the calendar. Anyone who can help me..You can also edit from here or a new code... Thanks!!
Cheers!
|
|
|
|
|
I'm sorry to say this, but your question is not very clear. Is English not your native language?
Here's what I *think* the problem is:
If you have a DateTime value, do NOT use the ToLongDateString() method as it formats the date depending on the user's Windows settings. Rather, use DateTime.ToString("yyyy-MM-dd") or whatever format the database accepts the date string in.
HTH.
Cheers,
Vikram. "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
|
|
|
|
|
Hi, Vikram.. Thanks for replying.. Actually, maybe what i explained is not very clear to you.. But actually, what i wants to do is that i've create a calendar and what i need to do now is that when i click on the date i've select it will show out the database of the user.. Is it clearer for you. As you've mention earlier on that i shouldn't write the ToLongDateString() if i using DateTime.ToString().. Can i ask you, then now how should i write the code so that it'll show out the database when i click on the date. Thanks!!
Cheers!
|
|
|
|
|
saddies wrote: what i need to do now is that when i click on the date i've select it will show out the database of the user
What do you mean by 'database of the user'?
Let's say you want to retrieve all the details of employees who joined on a certain date, from a table Employee. Assume that the user chose the date 01 Sept 2004, and that it is contained in the DateTime value userDate. Your query should look like:
string selectQuery = "SELECT * FROM Employees WHERE JoiningDate='" + userDate.ToString("yyyy-MM-dd") + "'";
Of course, the details will differ in your application, but you should get the general idea.
Cheers,
Vikram. "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
|
|
|
|
|
Well done, the OP was actually using paramaterized queries and you just taught him how to introduce Sql Injection attacks to his code.
|
|
|
|
|
Jamie, I took a look at your reply below and it's interesting - I didn't know that parameters are automatically converted at runtime. Thanks!
But what do you mean by 'introducing SQL injection attacks'?
Cheers,
Vikram. "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
|
|
|
|
|
|
Thanks, Jamie. Glad to have learnt something useful today.
Cheers,
Vikram. "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
|
|
|
|
|
Hi, I can see from your code that when a user selects a date, you display it to him apsolutely 100% perfectly!! It will be formatted according to HIS/HER windows settings
This line is perfect!
TBDate1.Text = CAL1.SelectedDate.ToLongDateString();
However, take 1 step backwards:
DateTime selectedDateTime = CAL1.SelectedDate;
Without the .ToLongDateString() call, you have a DateTime Object.
The only place you went wrong below is that you tried to parse the string back into a Date, which at best is unnecessary and at worst will not work.
SqlConnection conn=new SqlConnection("my connection string");
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Particulars WHERE DateField = @Date";
cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = DateTime.Parse(TBDate1.Text);
The beauty of parameters (especially date ones) is that the ADO.NET provider will take care of any conversion for you... so change the last line to:
cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = CAL1.SelectedDate;
simple, huh?
|
|
|
|
|
Hi,J4amieC.. Below is my code which i have changed.. But somehow when i run the program, the database does not show out when i click on the date. Is there's anything wrong or i still missing on some part??
DateTime selectedDateTime = CAL1.SelectedDate;
SqlConnection conn=new SqlConnection("my connection string");
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Particulars WHERE DateField = @Date";
cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = CAL1.SelectedDate;
Thanks for your help!!
Regards
|
|
|
|
|
I am now using Random r=new Random() to generate random number.
Now for debugging purpose, I want want my program to generate same random number every time i run it. I guess i need to use a fixed seed in order to do that. but i do not how. Can anyone please give me some suggestion?
Thanks
|
|
|
|
|
A quick search on MSDN:
public Random(int Seed);
Simply provide the same seed.
Cheers,
Vikram. "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
|
|
|
|
|
I like to use windows shell icons in my program as menuitem icons. How can i include those without extracting them first and then import as resource?
EG:
I have a file menu and would like to have a blank page icon next to the new file entry.
To learn to fly the hard way, you just have to jump and to forget to hit the ground. The rest comes with it.
|
|
|
|
|
Use a program like the free IrfanView to extract icon images out of the shell icon library file (shell32.dll).
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Bought a House!
Judah Himango
|
|
|
|
|
The question was, to do it without extracting them first.
Point is, that i have some example programs that do not have in included icons but show them in the menu. They aren't written in c# so maybe its something c# cant do, but i like to understand how it works.
Nothing is impossible, but to understand a woman.
|
|
|
|
|
Hi,
I am still new at C# and am coding an app that has tabs and on each tab is a treeview. I need to figure out which tab is selected and wich node on the treeview is selected for the current tab when the user clicks on certain menus.
I found a way to do it, but was wondering if there was an easier way.
TreeNode node;
string tabName = _tabs.SelectedTab.Text;
switch (tabName)
{
case "One" :
node = _tvwOne.SelectedNode;
break;
case "Two" :
node = _tvwTwo.SelectedNode;
break;
case "Three" :
node = _tvwThree.SelectedNode;
break;
}
Thanks in advance.
Sean
|
|
|
|
|
If you only have TreeView s on the tabs, you could use this code:
TreeView tv = ( TreeView ) tabControl1.SelectedTab.Controls[ 0 ];
TreeNode activeNode = tv.SelectedNode; Or, to get really terse:
TreeNode activeNode = ( ( TreeView ) tabControl1.SelectedTab.Controls[ 0 ] ).SelectedNode;
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
In reference to my previous post, you can use that code with TabPage s that have more than just the TreeView s on them. You just need to ensure that the TreeView is the FIRST control added to the TabPage .
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Thank you. That works great.
Sean
|
|
|
|
|
Happy to hear it. Keep on codin'!
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I have a binary data file saved as serialized object , when it is deserialized to datatable then binded to a datagrid , the user will make som changes to a record then save these changes back to the file , how can I save back the changed record ,do I have to serialize the all items each time when a one record updated , what is the right method to do so ,,, any help ;
thanx ........
|
|
|
|
|