Open aspx Page after WCF Callback - asp.net

I've the following problem:
I have to implemented a kind of a chat application. Therefore I use ASP.NET 4.5 and WCF. When I'm start click on the person I want to chat with, I call a wcf webservice. This webservice calls the wcf callback from the person I clicked on it. My problem is now, that I get the event called on the client side, but I am not able to open a new ChatWindow.
[CallbackBehavior(UseSynchronizationContext = false, ConcurrencyMode = ConcurrencyMode.Single)]
public class ChatContext : IChatClient, INotifyPropertyChanged
{
#region Events
public event EventHandler StartChat;
#endregion
public void FollowChatBegin(Person invitee)
{
StartChat(invitee, new EventArgs());
}
I have registered the StartChat Event in my main page:
public partial class MainPage: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// ...
Global.ChatContext.StartChat += ChatContextOnStartChat;
}
private void ChatContextOnStartChat(object sender, EventArgs eventArgs)
{
var person= (Person) sender;
string path = this.Request.Url.AbsoluteUri.Remove(this.Request.Url.AbsoluteUri.IndexOf(Request.Url.LocalPath, Request.Url.LocalPath.Length));
path += "/Controls/Chat/ChatWindow.aspx";
string parameters = "did=" + person.Id + "height=700px,width=800px,resizeable=yes,status=no";
path += parameters;
ScriptManager.RegisterStartupScript(this, this.GetType(), "openChartWindow", "window.open('" + path + "');", true);
this.upMain.Update();
}
}
ChatContextOnStartChat gives me the following problems:
this.Request is null
I cannot call my UpdatePanel.Update
I have no idea how I can simply open a pop up / dialog whatever... Can I just use a wrong pattern?

Related

What is the event name for start time in calendar of asp.net outlook 2007 add in?

I am very new in outlook 2007 add in project.
I would like to know the event name when I select the start time in calendar of outlook (as below code that I tried for event). Thanks in advance.
namespace OutlookAddIn1
{
public partial class ThisAddIn
{
private Outlook.Explorer currentExplorer = null;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
currentExplorer = this.Application.ActiveExplorer();
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
}
private void CurrentExplorer_Event()
{
Outlook.MAPIFolder selectedFolder = this.Application.ActiveExplorer().CurrentFolder;
String expMessage = "Your current folder is " + selectedFolder.Name + ".\n";
String itemMessage = "Item is unknown.";
try
{
expMessage = expMessage + itemMessage;
}
catch (Exception ex)
{
expMessage = ex.Message;
}
// MessageBox.Show(expMessage);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
I am not sure what this has to do with ASP.Net... Your C# or VB.Net addin can use the Explorer.SelectionChange event. Explorer object can be retrieved from Application.ActiveEXplorer
When the event fires, read the Explorer.CurrentView property, check if it is an instance of the the CalendarView object and use the CalendarView.SelectedStartTime and SelectedEndTime properties.

how to check string value and refresh the page in asp.net

i have a static string in static class, its getting value from desktop application,
on asp.net i have to check that its null or have value, if it has value , i want to
show it on label (on aspx page) , i have put a backgroud worker in global.asax,
public static BackgroundWorker worker = new BackgroundWorker();
public static int ID = 0;
// public static List<Person> personList = new List<Person>();
public static string personList;
public static bool stopWorker = false;
void Application_Start(object sender, EventArgs e)
{
worker.DoWork += new DoWorkEventHandler(DoWork);
worker.WorkerReportsProgress = true;
worker.WorkerSupportsCancellation = true;
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);
// Calling the DoWork Method Asynchronously
worker.RunWorkerAsync();
private static void DoWork(object sender, DoWorkEventArgs e)
{
//foreach (Person p in personList)
//{
personList = Class1.GetDataFromDesktop;
//}
}
its checking value time to time, but i am unable to show the response on label which is on aspx page
, what to do, is there any other process or i can do it using global.asax

Events from COM: works fine in WinForms/WPF but doesn't work in ASP.Net

Please tell me why does the following work fine in WinForms/WPF and not in ASP.Net.
We have a class library targeted for .Net 3.5. It has an interop referenced (generated from TLB).
public class MyClass
{
public delegate void ChangedEventHandler(string newStatus);
public event ChangedEventHandler Changed;
private ComObject objCom = new ComObject();
public void Init()
{
//Com events.
objCom.AvailabilityChanged += objCom_AvailabilityChanged;
//Start session to the h/w device.
//When finished, AvailabilityChanged event is fired with new h/w status.
objCom.StartSession("DeviceName");
}
void objCom_AvailabilityChanged(ComStatus status)
{
//Fired when session is started.
Changed(status.ToString());
}
}
And then i have a WinForms/WPF application (targeted for .Net 4.5) that creates a new instance of MyClass, subscribes to the Changed event and calls Init().
This works perfectly.
I'm trying to do the same in ASP.Net web forms application. The Init() method is being called, but the objCom_AvailabilityChanged event in MyClass is never fired.
public partial class WebForm1 : System.Web.UI.Page
{
private MyClass test = new MyClass();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
test.Changed += test_Changed;
test.Init();
}
void test_Changed(string newStatus)
{
TextBox1.Text = newStatus;
}
}
Please explain what am i doing wrong.
Thanks a lot!

WCF\ASP.NET interoperability

I have a server application written in WCF using asynchronous callbacks, and a webforms application in ASP.NET.
All of the communication is fine between the 2 applications, I can call the exposed functions in the server via the web application, and the server can send callbacks to the web application, however sometimes the functions within the callback work, and other times, they don't.
For example, I would like a login button on the web app to send a username and password to the server, the server checks this against the database, and if the login information is correct, it should send a callback, which opens a new page in the web app.
Here is the relevant server code:
public void Login(String username, String password)
{
//DoCheckAgainstDatabase(username, password);
ICallback callback = OperationContext.Current.GetCallbackChannel<ICallback>();
callback.LoginSuccess();
}
and the web application code:
private InstanceContext _instanceContext;
private ServiceClient _service;
public CallbackHandler MyCallbackHandler = new CallbackHandler();
protected void Page_Load(object sender, EventArgs e)
{
_instanceContext = new InstanceContext(MyCallbackHandler);
_backEnd = new ServiceClient(_instanceContext, "NetTcpBinding_IAU", "net.tcp://localhost/MyService/Service");
_backEnd.Open();
MyCallbackHandler.LoginSucceeded += OnLoginSucceeded;
}
protected void LoginButton_Click(object sender, EventArgs e)
{
_backEnd.Login(UsernameTextBox.Text, PasswordTextBox.Text);
}
private void OnLoginSucceeded(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "OpenClientWindow", "window.open('Client.aspx','_self');", true);
}
I can put in breakpoints, and see that everything is working fine, it's just that the code 'ScriptManager.RegisterStartupScript...' does not execute properly all the time.
Could this be something to do with threading? Could anyone suggest a way to fix this please?
Thanks in advance!
David
It occurs to me that it's possible your page life cycle may be ending - or at least getting to the Render stage, which is where the start up script would be written to the output - before the callback is called.
Is it possible to call your service synchronously, and not proceed out of LoginButton_Click until the service call returns?
I think you are missing script tag - wrap your window.oppen with it, like
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "OpenClientWindow", "<script>window.open('Client.aspx','_self');</script>", true);
Thank you Ann L. for guidance on this. I have added a ManualResetEvent, and then in the button click method, I wait until I have received the callback, then proceed with opening the new page:
private InstanceContext _instanceContext;
private ServiceClient _service;
public CallbackHandler MyCallbackHandler = new CallbackHandler();
private ManualResetEvent _resetEvent = new ManualResetEvent(false);
protected void Page_Load(object sender, EventArgs e)
{
_instanceContext = new InstanceContext(MyCallbackHandler);
_backEnd = new ServiceClient(_instanceContext, "NetTcpBinding_IAU", "net.tcp://localhost/MyService/Service");
_backEnd.Open();
MyCallbackHandler.LoginSucceeded += OnLoginSucceeded;
}
protected void LoginButton_Click(object sender, EventArgs e)
{
_backEnd.Login(UsernameTextBox.Text, PasswordTextBox.Text);
_resetEvent.WaitOne();
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "OpenClientWindow", "window.open('Client.aspx','_self');", true);
}
private void OnLoginSucceeded(object sender, EventArgs e)
{
_resetEvent.Set();
}

textBox onBlur to call server method instead of client method

I'm extending a web control. I need to call server methods on every event fired by the control instead of javascript.
public partial class MyTextBox : RadTextBox, IScriptControl
{
public MyTextBox()
{
Attributes.Add("onBlur", "handleLostFocus();");
Attributes.Add("runat", "server");
}
public void handleLostFocus()
{
MyObject obj = new MyObject();
obj.someproperty = this.Text; //or somehow get the user entered text.
MyService1 service = new MyService1();
service.sendRequest(obj);
}
}
As I said in my comment, TextBox will post by default if AutoPostBack = "True", however, you need to handle your event. Supposing your TextBox is named TextBox1:
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
string str = TextBox1.Text;
}
Get rid of handleLostFocus() or have it be the handler for your TextBox control.
Good luck mate.

Resources