Pass data between web forms inside ASP.NET - c#

In Winforms I Can do following
protected void SomeButonClick(object sender, EventArgs e)
{
ChildForm cf = new ChildForm();
cf.Grid = ParentForm.Grid
cf.ShowDialog();
//and so on
}
How I can accomplish something similar in ASP.NET WebForms.

There are a number of ways to approach this in ASP.NET. Your use of "ShowDialog" suggests to me that you will get what you want out of using jquery to launch a modal popup. There are several canned tools for this, like jquery popup.

Related

Using Form 1 while Form 2 is open - C#

I have used Google to find a solution on this without any luck, hoping you guys/girls can help me out.
Code :
private void funButtonToolStripMenuItem_Click(object sender, EventArgs e)
{
var FF = new FunForm();
FF.ShowDialog();
}
Very simple, opens up a second Form.
However, when this form launches it disables access to my main form.
Am I able to prevent this from happening?
Use FF.Show() rather than FF.ShowDialog()
Is FF.Show() what you want? It displays the second form non-modal. See MSDN for details.

C# Winforms WebBrowser open links in default browser

I know this has been discussed several times around here but the default behaviour for opening links
clicked in a WebBrowser control does not work for my application.
So while this works as in it opens a link clicked in IE:
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
System.Diagnostics.Process.Start(e.Url.ToString());
e.Cancel = true;
}
I am using a dropdown list to update the html file that the webBrowser is displaying like so:
private void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
webBrowser1.Url = myURI;
}
Now the problem I'm having is that with the _Navigating method above, the webBrowser does not load any subsequent changes to the URL (thanks to the e.cancel I guess) so it only displays the first html file it loads.
If I remove the _Navigating method it updates fine but then the links open up in the same webBrowser control which is what I do not want.
How can I get it to work both ways?
I hope this can help you.
If you want to open a link in a browser, you can add this simple code:
Process.Start("http://google.com");
Remember, there is a lot of information about it. Here in stack Overflow you can take a look in this post: How to open in default browser in C#
If you want to open your link in another browser, you can use this code:
System.Diagnostics.Process.Start("firefox.exe", "http://www.google.com");
Don't forget to visit this post called: How do I open alternative webbrowser (Mozilla or Firefox) and show the specific url?
And Finally, I could recommend you this stack overtflow post called: .NET C#: WebBrowser control Navigate() does not load targeted URL
I hope this information can help you a little bit.
This is an old post but I believe I may understand what the original poster wanted to do. They wanted a page to load in the webbrowser control if the user selected it from the dropdown list but any links in the loaded page should open in the user's web browser. If this is indeed the case, the original poster need a flag on the form to determine the behavior.
The original poster simply needed a flag such as linksOpenInSystemBrowser shown below.
using System;
using System.Windows.Forms;
namespace Browser_Test
{
public partial class myForm : Form
{
private bool linksOpenInSystemBrowser = false;
public myForm()
{
InitializeComponent();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
linksOpenInSystemBrowser = false;
webBrowser1.Navigate(comboBox1.SelectedItem.ToString());
}
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if(!linksOpenInSystemBrowser)
{
linksOpenInSystemBrowser = true;
return;
}
System.Diagnostics.Process.Start(e.Url.ToString());
e.Cancel = true;
}
}
}

Managing _blank links

I'm using xulrunner to show some content from a website, it works perfectly for the most, but we have included a facebook like box with stream (div+javascript), and clicking on any link in it does nothing.
We would like to open it in a new window of the default browser, it's possible?
the code for the xulrunner is pretty simple
private void Form_browser_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
geckoBrowser.Navigate(Properties.Settings.Default.redirect);
}

Updating Form1's widgets by clicking Form2's button in Visual C# Windows Forms

I'm fairly new to Visual C# and I'm writing an GUI app with multiple forms. One form is main window, and the rest are some kind of option windows. When showing an option window, I need to load some data to it (for example a string to window's editbox), then edit it and return back to main window when closing option window. Is there any simple way I can achieve it?
I've found some solutions like, or c# event handling between two forms, but I can't really conform it to my needs. I was thinking about passing data in constructor, but how to get it back? I've found something about ShowDialog, but as I said I'm new to C# (started yesterday ^^) and don't know if I can use it.
Any ideas, please?
I found the following previous answer which outlines sending specific properties from the one form to another:
Send values from one form to another form
The using keyword will also ensure that the form is cleaned-up properly, here's a link to it's usage (pardon the pun...) : http://msdn.microsoft.com/en-us/library/vstudio/yh598w02.aspx
I've run into the same issue to be honest, and I have to say that prior to this discussion I would just pass the parent form itself to the child and alter it in that way. Such as:
ChildForm child = new ChildForm(this); //from the parent
and
public ChildForm(ParentForm parent)
{
this.parent = parent;
}
Probably not the best convention though, as you probably don't need to access that much from the parent as the child.
Thanks guys, I think I finally get it. Idle_Mind, your idea was the easiest in my point of view, so I decided to use it. If someone else has a problem like this, here's what I've coded:
In main window form: when button is clicked, a new form appears; after closing it, label1 shows the text typed in that form
private void Button1_Click(object sender, EventArgs e)
{
LoadDataForm loaddata = new LoadDataForm("initial value");
if (loaddata.ShowDialog() == DialogResult.OK)
{
label1.Text = loaddata.textBox1.Text;
}
}
In load data form: argument passed in form's constructor appears in textBox1; textBox1's Modifiers property has to be modified to "public"
public LoadDataForm(string initvalue)
{
InitializeComponent();
textBox1.Text = initvalue;
}
private void ApplyButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
Regards,
mopsiok

How to Implement NavigationService in Silverlight

My Silverlight application has multiple XAML pages. For example, one displays a clock, one displays a timer. I have buttons to switch back and forth like so:
private void switchRight(object sender, RoutedEventArgs e)
{
this.Content = new Clock();
}
private void switchLeft(object sender, RoutedEventArgs e)
{
this.Content = new Timer();
}
I am trying to use the NavigationService to switch back and forth so I can have other pages running in the background rather than creating a new instance each time.
I am trying
NavigationService.Navigate(new uri("/Timer.xaml", UriKind.Relative));
but it doesn't seem to do anything and I can't find any good examples to help.
Here is a link
http://blogs.msdn.com/b/dphill/archive/2009/04/28/silverlight-navigation-part-3.aspx ,
Beside, I think you can use Threading for background processes.i.e.when you start a timer no need to show any xaml.
But for page instances you need to manage it very carefully otherwise stackoverflow :)
Depending on business rules its hard to decide navigation as being in a web browser.
We created our own Wizard (with rules). You may create your own NavigationManager. For validation I can offer http://fluentvalidation.codeplex.com/

Categories