|
Hi to everyone,
I'm just trying to pass parameter to a JavaScript function from C# code.
The parameterless function is as shown in part1, but I want it to be parametric therefore, I made a bit changes as shown in part2:
--- part1 ---
function next(){
var pass = document.getElementById("ctl17_password");
if(window.event && window.event.keyCode == 13) {
pass.focus();
return false;
}
else
return true;
}
In C# I use the below code:
UserName.Attributes.Add("onkeypress", "return next()");
THIS WAY EVERYTHING IS OK.
-------------
--- part2 ---
function next(parameter) {
var pass = document.getElementById(parameter);
if (window.event && window.event.keyCode == 13) {
pass.focus();
return false;
}
else
return true;
}
In C# I use the below code:
UserName.Attributes.Add("onkeypress", "return next(ctl17_password)"); --- BUT THIS DOES NOT WORK, I'm not also sure about passing the "parameter" variable as: getElementById(parameter);
-------------
I made some search on this issue, but couldn't find exactly what I needed. Could you please help me?
Thank you very much
Regards,
codddy
|
|
|
|
|
This is an ASP.NET question, not one for the C# forum.
Anyway, the corect way to do this it to use:
UserName.Attributes.Add("onkeypress", string.Format("return next('{0}');", password.ClientID)); Never hardcode the control name of an ASP.NET control into JavaScript methods. If you move where this control is situated, the ID changes because ASP.NET mangles the ID to ensure uniqueness.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi Pete, thanks a lot for your answer.
Yes, I was aware that hardcoding was wrong, but because of some urgent reasons I had to do it. Thanks again.
I would like to ask one more question.
I used your way and everything works fine locally. But on the server it does not even come to JavaScript function?
Do you have any idea about this issue?
Regards,
coddy
|
|
|
|
|
Hi,
In a form i have so many panels and controls
when i increase one panel it overrides another controls. scroll bars are not comming.
dock style is fixed at bottom.
|
|
|
|
|
hmm... interesting.
var question = (_2b || !(_2b));
|
|
|
|
|
In order to get some help you will have to describe your problem a little better.
Is this happening at run-time or design-time?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Its run time.
i set above controls panel's dock style is fill and
down panel's dock is bottom. (this is fixed for my requrement)...
|
|
|
|
|
In that case investigate 'Z order'.
If you are still stuck after reading up on that, post back and I will try to help.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi I am given with a project where advertisements are added in between serials. So for that we need to first split the video file into pieces and merge it with those advertisements. Can anyone help me out in this.
|
|
|
|
|
I dont think this is the right forum to ask this.
Are you trying to split the video files with your own software written in c#???
Have a Happy Coding.....
|
|
|
|
|
Hi everyone,
I've got a dialog box with checkboxes, comboboxes and textboxes for filling in. I have it saving perfectly into my access database. On this dialog I have Load button, which opens a new dialog. This has a search textbox, a datagridview and a few buttons. The datagridview displays the contents of the database.
I would like to be able to get the information in the selected row of the datagridview and load that into the original dialog. I have tried to figure it out myself, but my C# knowledge is limited.
I don't really have any code for loading, but If i write anything i'll get it posted.
Any direction in this would be greatly appreciated.
Many thanks
Martin
|
|
|
|
|
Hi Martin,
Take a look at 'DataGridViewRow'.
That should get you started.
If you cannot get it working, post back with an example of what you have tried, and I will try to help.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks.
I've had a play with that previously, couldn't really figure out out to implement it though, I'll just keep going.
|
|
|
|
|
Hi Martin,
The DataGridView has a property called SelectedRows , which is a collection of the rows currently selected. There is also an event called OnRowEnter . Both of these give you access to the DataGridViewRow selected by your user. What is needed is a way to track that row and make it available to your calling form when the dialog closes. So:
1. add a private field to your dialog.
private DataGridViewRow selectedRow;
2. add a public property so that it can be accessed from outside the dialog
public DataGridViewRow SelectedRow
{
get
{
return this.selectedRow;
}
}
3. If you elect to use OnRowEnter , for example, you can store the row in the private field. In the event handler:
this.selectedRow = this.dataGridView1.Rows[e.rowIndex];
then every time a new row is entered that row is stored in your field.
4. In your calling form:
if (datagridDialog.ShowDialog() == DialogResult.OK)
{
this.FillData(datagridDialog.SelectedRow);
}
private void FillData(DataGridViewRow loadedRow)
{
this.usernameTextBox.Text = loadedRow.Cells["UserName"].Value.ToString();
etc.
}
Hope this gives you some idea.
It has just occurred to me that your calling forms controls might be databound, if so this won't work, please let me know.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks alot for that.
I've found a simpler way to get the cell value. I'm just getting the value from the datagridview with:
class1.UserID = dtaSearchID.SelectedRows[0].Cells[0].Value.ToString();
I do that for all the cells in the selected row.
The problem I have now is that I'm not asure how to automatically fill those details into the first dialog. I am able to do it when i manually trigger an event, ie. click another button. But I can't figure out how to do it on the click of the load button in my Search from.
Any help greatly appreciated.
Martin
|
|
|
|
|
One solution to this is not to handle the button-click event in the search form, but in your first dialogue.
This is one reason that I suggested the public DataGridViewRow SelectedRow property in my previous post.
In your Search dialogue:
public event EventHandler LoadButtonClick
{
add
{
this.loadButton.Click += value;
}
remove
{
this.loadButton.Click -= value;
}
}
doing it this way keeps to OOP principles. Of course if you want to 'cheat' just change the Modifier property for the button, in the properties window, to public .
You will have to declare a reference to the Search dialogue as a field of the first dialogue:
public class FirstDialog : Form
{
private SearchDialog sd = null;
........
........
........
........
Then in the first dialogue, where you create the search dialogue, something like:
using (sd = new SearchDialog())
{
sd.LoadButtonClick += MyLoadButtonClickHandler;
if (sd.ShowDialog() == DialogResult.OK)
{
sd.LoadButtonClick -= MyLoadButtonClickHandler;
}
else
{
sd.LoadButtonClick -= MyLoadButtonClickHandler;
}
}
The click handler can then do
private void MyLoadButtonClickHandler(object sender, EventArgs e)
{
this.UserNameTextBox.Text = sd.SelectedRow.Cells["UserName"].Value.ToString();
etc.
}
Hope this gives you some ideas.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks so much, that works beautifully.
Not entirely sure exactly how it works, but I'll work it out hehe.
Many thanks
Martin
|
|
|
|
|
Hi Guys,
I am working on a Windows Form where I have placed a Button control (Button text: Exit). In the Button1_Click event Handler, I have added this code:
//Code begins here
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Are you sure to exit the application! Selct Ok to Exit now or Cancel to stay in the current form", "Sample App", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (MessageBox.Show("Are you sure to exit the application! Selct Ok to Exit now or Cancel to stay in the current form", "Sample App", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
{
Close();
}
else
{
return;
}
}
//Code ends here
However, when I debug the solution and click on the Exit button, the Message Box is displayed asking for confirmation. Then, when I click on the Ok button, instead of closing the application, the same Message Box pops up again! Then, again I have to click on Ok and this time the Click Event executtes and the application closes. Similar is the case with the Cancel Button. Why does the MessageBox display the same message twice? Help me Please....
Your help will be appreciated. Thanx....
|
|
|
|
|
youve now posted te same question again a mere 10 minutes later.
READ THE CODE. STEP THROUGH THE CODE. IT IS OBVIOUS WHY YOU GET TWO MESSAGE BOXES.
I thought you might be hard-of-reading so i shouted that in the typical englishman manner of just talking louder and slower to foreigners in english.
|
|
|
|
|
|
Kwagga wrote: Newby and Hoemwork
Newbie and Homework
"Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)
|
|
|
|
|
Hello there,
Plz dont shout at me! I am only a newbie here. If I'm finding something difficult to understand, then its your sole responsibility to help me out. I know that there's some mistake with the code, but am unable to mark it out..... Please give me a hint.
Your help will be appreciated...
thanx
|
|
|
|
|
Rajdeep.NET wrote: Please give me a hint.
You're kidding, right? You've had so many hints already that if you cant work it out now its time to hand back your textbooks, cancel your account with your college computer centre, and go get a job flipping burgers.
|
|
|
|
|
J4amieC wrote: and go get a job flipping burgerscow patties .
Fixed that for you.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Rajdeep.NET wrote: its your sole responsibility to help me out
It will be Jamie's responsibility to help you out when you pay him for it.
|
|
|
|