How to pass and use web page to an external class?
-
Given: (I am new to web programming) 1. Visual Studio 2013, C# / VB 2. I have a front end C# Web app that handles the UI. 3. The C# page code behind calls a vb class in an external DLL to do the business logic. 4. The VB business class needs to update info on the UI page with status, etc. as it is running so it needs access to the Page. How do you pass the page to the VB constructor? I have tried various options as: C#
VBMain VBM;
VBM = New VBMain(this);with VB VBMain ... Sub New(pWebCtl as Object) .
Dim MyLblMsg as System.Web.UI.WebControls.Label = pWebCtl.FindControl("lblMsg")
but MyLblMsg is always nothing. How do you pass and use the web page? If I pass the label itself I do get it but would need an UpdatePanel to have it update. (This would be put in once I get the basics working). How to pass and use web page to an external class?
What exactly you need.Why you need to pass web page to a class.what you do in the external class with the web page. if you provide more details of what you want to do and what you are expecting as result ,It will help others to provide you answer. I think from your web page you want to pass some parameter to your external class method and do some action in that class and the method will return the data to your UI. If this is correct then explain more detail of your requirement.
-
What exactly you need.Why you need to pass web page to a class.what you do in the external class with the web page. if you provide more details of what you want to do and what you are expecting as result ,It will help others to provide you answer. I think from your web page you want to pass some parameter to your external class method and do some action in that class and the method will return the data to your UI. If this is correct then explain more detail of your requirement.
The external class does all the business functions of the app which is basically importing a file into QuickBooks. These files can be large. At various times we would like to send back some status as Done nn records, nnn to go. Orders=nnn, etc. The plan was to use the passed form so that the external class could do a pForm.lblMsg.text = "Done nn records, nnn to go. Orders=nnn, etc." and somehow the UpdatePanel which contains lblMsg would be posted back to the user. Currently the main page which handles screen ui functions contains a upload control that uploads the file to the server and then invokes the external class via the constructor to process that uploaded file. The VB business class is very extensive. If there is a better way please let me know.
-
Given: (I am new to web programming) 1. Visual Studio 2013, C# / VB 2. I have a front end C# Web app that handles the UI. 3. The C# page code behind calls a vb class in an external DLL to do the business logic. 4. The VB business class needs to update info on the UI page with status, etc. as it is running so it needs access to the Page. How do you pass the page to the VB constructor? I have tried various options as: C#
VBMain VBM;
VBM = New VBMain(this);with VB VBMain ... Sub New(pWebCtl as Object) .
Dim MyLblMsg as System.Web.UI.WebControls.Label = pWebCtl.FindControl("lblMsg")
but MyLblMsg is always nothing. How do you pass and use the web page? If I pass the label itself I do get it but would need an UpdatePanel to have it update. (This would be put in once I get the basics working). How to pass and use web page to an external class?
Passing a web page as a parameter to a function seems very clunky. You don't generally pass UI objects as parameters, but instead pass their values. If your DLL needs certain values in order to give certain results, then simply pass it the values it needs, not the entire web form. Pass the DLL only what it needs in order to give you the results you require.
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare Home | LinkedIn | Google+ | Twitter
-
Passing a web page as a parameter to a function seems very clunky. You don't generally pass UI objects as parameters, but instead pass their values. If your DLL needs certain values in order to give certain results, then simply pass it the values it needs, not the entire web form. Pass the DLL only what it needs in order to give you the results you require.
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare Home | LinkedIn | Google+ | Twitter
I understand that but that is NOT what I need to do. So are you saying that there is no way to pass the entire page as a parameter???
-
I understand that but that is NOT what I need to do. So are you saying that there is no way to pass the entire page as a parameter???
No I didn't say you could not pass the web page. I am asking you to clarify why you need to pass the entire web page to the DLL in the first place. Can you please explain why you want to pass a web page to a DLL.
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare Home | LinkedIn | Google+ | Twitter
-
No I didn't say you could not pass the web page. I am asking you to clarify why you need to pass the entire web page to the DLL in the first place. Can you please explain why you want to pass a web page to a DLL.
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare Home | LinkedIn | Google+ | Twitter
Sorry. Wanted the web page so we can take advantage of all the methods, etc. available. Updating of various status fields and perhaps responses (if we could figure out how). Since Asp Net is new to us and we are converting from Desktop to Web we need to be able to learn as well as get the job done. We are already behind in the project. One of the major problems is how to do the desktop equivalent of MsgBox (MessageBox.show) and get the results in the middle or processing e.g. importing a file that has been running for a few minutes as record 500 of 1000 just to find there is some type of problem as in the data, etc. In the Desktop app we would put something like
RetB = MsgBox("Hit Yes to continue as is, No to Skip, Cancel to abort", VBYesNoCancel).
if Retb = VBVancel then
GoTo ExitFunction
ElseIf Retb = VBYes then
ElseIf RetB = VBNo then
EndifThe program execution stops and then resumes when the user hits Yes, no or cancel. This is not that easy in a Web app and currently not even sure how to do it. Certainly do not want a postback to come back in and we have to start all over or loss the variables, etc. Any ideas would be appreciated. Thanks and have a Great 2015!
-
Sorry. Wanted the web page so we can take advantage of all the methods, etc. available. Updating of various status fields and perhaps responses (if we could figure out how). Since Asp Net is new to us and we are converting from Desktop to Web we need to be able to learn as well as get the job done. We are already behind in the project. One of the major problems is how to do the desktop equivalent of MsgBox (MessageBox.show) and get the results in the middle or processing e.g. importing a file that has been running for a few minutes as record 500 of 1000 just to find there is some type of problem as in the data, etc. In the Desktop app we would put something like
RetB = MsgBox("Hit Yes to continue as is, No to Skip, Cancel to abort", VBYesNoCancel).
if Retb = VBVancel then
GoTo ExitFunction
ElseIf Retb = VBYes then
ElseIf RetB = VBNo then
EndifThe program execution stops and then resumes when the user hits Yes, no or cancel. This is not that easy in a Web app and currently not even sure how to do it. Certainly do not want a postback to come back in and we have to start all over or loss the variables, etc. Any ideas would be appreciated. Thanks and have a Great 2015!
I understand your need to get something working quickly, but equally you don't want to make bigger problems for yourselves further down the road. By passing the web page to your DLL you are creating a dependency which will make future development and maintenance difficult to say the least. Firstly I would move all the code that is currently embedded in your web page to a separate class that can be invoked by your web page or any other class that requires it. This removes any dependency and gives you more flexibility going forwards. There are many different ways in which to display messageboxes on a web page. You'll need a basic grasp of javascript. Here's just example of how it can be accomplished http://www.aspsnippets.com/Articles/Display-MessageBox-in-ASP.Net-using-JavaScript.aspx[^]
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare Home | LinkedIn | Google+ | Twitter
-
I understand your need to get something working quickly, but equally you don't want to make bigger problems for yourselves further down the road. By passing the web page to your DLL you are creating a dependency which will make future development and maintenance difficult to say the least. Firstly I would move all the code that is currently embedded in your web page to a separate class that can be invoked by your web page or any other class that requires it. This removes any dependency and gives you more flexibility going forwards. There are many different ways in which to display messageboxes on a web page. You'll need a basic grasp of javascript. Here's just example of how it can be accomplished http://www.aspsnippets.com/Articles/Display-MessageBox-in-ASP.Net-using-JavaScript.aspx[^]
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare Home | LinkedIn | Google+ | Twitter
The main pages are C#. I have not been able to convert it to VB (our main language). Gave up on it. Was always getting some type of load problem on startup. I do not remember the details. Most of the samples for MsgBox(MessageBox.Show) only display and do not discuss in detail the main points. 1. Getting a response i.e. Yes, No, Cancel back to the invoking code. 2. This has to suspend the invoking code and not do any type of postback since the process might have been running for many minutes and do not want to restart and loose memory variables and other objects which can be time consuming. It is not clear how to preserve these variables and objects if any type of postback is to be done. The idea was to make the web app run as the desktop app. 1. Status of where we are in the process i.e. Record #, name, etc. 2. Ability to do a MsgBox to ask user in case of problems as to what to do. I guess that we could retry to convert or re-code the C# pages to VB again if that is the best approach.
-
Given: (I am new to web programming) 1. Visual Studio 2013, C# / VB 2. I have a front end C# Web app that handles the UI. 3. The C# page code behind calls a vb class in an external DLL to do the business logic. 4. The VB business class needs to update info on the UI page with status, etc. as it is running so it needs access to the Page. How do you pass the page to the VB constructor? I have tried various options as: C#
VBMain VBM;
VBM = New VBMain(this);with VB VBMain ... Sub New(pWebCtl as Object) .
Dim MyLblMsg as System.Web.UI.WebControls.Label = pWebCtl.FindControl("lblMsg")
but MyLblMsg is always nothing. How do you pass and use the web page? If I pass the label itself I do get it but would need an UpdatePanel to have it update. (This would be put in once I get the basics working). How to pass and use web page to an external class?
Consider this. The .dll exists on the server. Even if you did have a msgbox, that code is not running on the client - client would never see this msgbox. Why not instantiate the class in code-behind of the webpage and access methods that way. It makes no matter that it is a vb.net class. The class methods will need to return results that can then be used to render on the page as necessary. MsgBox in server code for website can cause much grief.
There are strangers on the Plain, Croaker
-
Consider this. The .dll exists on the server. Even if you did have a msgbox, that code is not running on the client - client would never see this msgbox. Why not instantiate the class in code-behind of the webpage and access methods that way. It makes no matter that it is a vb.net class. The class methods will need to return results that can then be used to render on the page as necessary. MsgBox in server code for website can cause much grief.
There are strangers on the Plain, Croaker
I understand that MsgBox is a Server type of function and would not work which is why I am looking for a replacement. I do see that there are various 'push' techniques to push data to a web page without the user doing anything like in streaming or a chat box. Surely something can be done that is similar. Somehow to keep the connection open and keep sending responses. The VB class works now and to move the function calls to the main C# page handler would take a long time. Or perhaps I do not understand what you mean.