Showing posts with label itself. Show all posts
Showing posts with label itself. Show all posts

Thursday, March 29, 2012

newbie: how to print stuff at the shell using C# while at programming in asp.net

Hi, I made myself a componment, so it can talk to the database.
I want to able to see the certain value within the code itself. And I'm unable to use asp:label control.
Is there's any way I can print stuff on the shell so I can keep track of where I'm at with my varable?
I tried Console.Write(temp); but it didn't seem to work :(
TIA
Use one of the System.Diagnostics.Debug.Writexxx() methods. These will appear in the Output Window in Visual Studio as you run the site under the debugger.
Alternatively, use the HttpContext.Current.Trace.Write() method, and this will put output into the ASP.NET Trace, which you can either see on the page or via the trace.axd handler.

Thank you very much DMW, System.Diagnostics.Debug.Writexxx() is useful

case close

Saturday, March 24, 2012

Newbie: Selecting image from separate aspx page

I have a form where the user can select an image filename. Clearly it
would be better to allow them to select the image itself rather than key
in the filename.

So, I have a server side directory with the available images. And I have
a page which shows the images as ImageButtons.

My question is: What's the best way to link the two?

Should MyForm.aspx redirect to ImageList.aspx passing "MyForm" in the
query string so that ImageList knows where to redirect back to? It works
but it seems a bit convoluted so I think it must be wrong.

How do you solve this when basically you want to pick from a list of
things which aren't on the calling page?

Hope this makes sense.

In the desktop app environment I'd just open a dialog box. what is the
asp.net paradigm?You could simulate a dialog box by using window.open("ImageBox.aspx")
and then add some javascript in the onclick of the Select Button in
the ImageBox codebehind, which
- sets the image in the calling page (window.opener.getElementByID...)
- closes the imagebox window

So - mainly you have to deal with some javascript and DHTML

As to your original question: For easy pageflows I just put the
refering
page in the session/context items/request, which is not elegant, but
simple.
Alternatively you can implement a pageflow manager which can take
care of more complex navigations. Also worth looking at is
Server.Execute instead of redirect or transfer (and having a refering
page property defined in a page base class). There are really
a lot of options here and it is up to your preferences and requirements
to decide which one you want to go with.

-Stefan

Newbie: Selecting image from separate aspx page

I have a form where the user can select an image filename. Clearly it
would be better to allow them to select the image itself rather than key
in the filename.
So, I have a server side directory with the available images. And I have
a page which shows the images as ImageButtons.
My question is: What's the best way to link the two?
Should MyForm.aspx redirect to ImageList.aspx passing "MyForm" in the
query string so that ImageList knows where to redirect back to? It works
but it seems a bit convoluted so I think it must be wrong.
How do you solve this when basically you want to pick from a list of
things which aren't on the calling page?
Hope this makes sense.
In the desktop app environment I'd just open a dialog box. what is the
asp.net paradigm?You could simulate a dialog box by using window.open("ImageBox.aspx")
and then add some javascript in the onclick of the Select Button in
the ImageBox codebehind, which
- sets the image in the calling page (window.opener.getElementByID...)
- closes the imagebox window
So - mainly you have to deal with some javascript and DHTML
As to your original question: For easy pageflows I just put the
refering
page in the session/context items/request, which is not elegant, but
simple.
Alternatively you can implement a pageflow manager which can take
care of more complex navigations. Also worth looking at is
Server.Execute instead of redirect or transfer (and having a refering
page property defined in a page base class). There are really
a lot of options here and it is up to your preferences and requirements
to decide which one you want to go with.
-Stefan
Thanks Stefan.
I guess the session is a better place rather than clogging up the
querystring. I think I need a bit of practise to get into Web way of
doing things.
Colin
Stefan wrote:
> You could simulate a dialog box by using window.open("ImageBox.aspx")
> and then add some javascript in the onclick of the Select Button in
> the ImageBox codebehind, which
> - sets the image in the calling page (window.opener.getElementByID...)
> - closes the imagebox window
> So - mainly you have to deal with some javascript and DHTML
> As to your original question: For easy pageflows I just put the
> refering
> page in the session/context items/request, which is not elegant, but
> simple.
> Alternatively you can implement a pageflow manager which can take
> care of more complex navigations. Also worth looking at is
> Server.Execute instead of redirect or transfer (and having a refering
> page property defined in a page base class). There are really
> a lot of options here and it is up to your preferences and requirements
> to decide which one you want to go with.
> -Stefan
>

Newbie: Static Method Instantiating Itself To Acess Non-static Propertys. Ok?

Hello,

I am newbie to the group so hi all! My name is Jim and I am a
codaholic. Ok so now that is out of the way.

I am new to using all things static and I am wondering if what I am
doing is going to get me in trouble.

I am using the component designer to build my Sql Server objects for
me. I then expose methods such as getDataSet as static methods. In
order to leverage the non-static properties that the designer creates
for me I instantiate a new object of the component designer and set its
properties accordingly (mainly the SqlServer connection on the command
objects so that each Sql server command has its own connection).

One thing of note:

1.) Private methods are exposed to the New Instance of the component
designer inside of the static method. (Makes me a bit concerned that
something funny is going on)

The code below gives an example.

using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Data.SqlClient;

namespace GoDAT.Venue
{

public class Venue : System.ComponentModel.Component
{
// ~~~~
// ~~~~
#region CONSTRUCTOR
public Venue(System.ComponentModel.IContainer container)
{
container.Add(this);
InitializeComponent();
}
public Venue()
{
InitializeComponent();
}
#endregion
// ~~~~
// ~~~~

// ~~~~
// ~~
#region DISPOSAL
protected override void Dispose( bool disposing )
{
//blah, blah, blah
}
#endregion

private System.Data.SqlClient.SqlCommand sqlSelect_Venue;
private System.Data.SqlClient.SqlCommand sqlInsert_Venue;
private System.Data.SqlClient.SqlCommand sqlUpdate_Venue;
private System.Data.SqlClient.SqlCommand sqlDelete_Venue;
private System.Data.SqlClient.SqlDataAdapter sqlDA_Venue;
private GoDAT.Venue.dsVenue dsVenue1;
// ~~~~~
// ~~~~~

// ~~~~
// ~~~~
#region Component Designer generated code
// ALL THAT GREAT CODE GENERATED FOR FREE!!!!
// Or rather for the price of VS.NET and the
// hours of trial and error trying to figure
// out how to best leverage it.
#endregion
// ~~~~
// ~~~~

// ~~~~
public static GoDAT.Venue.dsVenue Get_dsVenue()
{

Venue tmpThis = new Venue();
GoDAT.Venue.dsVenue tmpDS = tmpThis.dsVenue1;
SqlDataAdapter adapter = tmpThis.sqlDA_Venue;

tmpThis.sqlSelect_Venue.Connection = SQLConnMgr.GetSqlConn();
tmpThis.sqlSelect_Venue.Connection.Open();
try
{
adapter.Fill(tmpDS);
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(("[Get_dsVenue] Exception " +
e.Message));
}
finally
{
adapter.Dispose();
tmpThis.sqlSelect_Venue.Connection.Close();
tmpThis.sqlSelect_Venue.Connection = null;
tmpThis = null;
}

return tmpDS;
}
// ~~~~~
}
}"Electric Co." <jmcphee@.ucalgary.cawrote in message
news:1155145846.449750.188470@.m79g2000cwm.googlegr oups.com...

What you did seems to be ok, however I would create a private static field
to your class and create your Venue object there. E.g

private static Venue venue = new Venue();

Then this variable could be access by all other methods in this class and
you only have to create this object once. Also, if you want to prevent this
class from begin created by some client code you could also make your
constructor private.

HTH

Quote:

Originally Posted by

Hello,
>
I am newbie to the group so hi all! My name is Jim and I am a
codaholic. Ok so now that is out of the way.
>
>
I am new to using all things static and I am wondering if what I am
doing is going to get me in trouble.
>
I am using the component designer to build my Sql Server objects for
me. I then expose methods such as getDataSet as static methods. In
order to leverage the non-static properties that the designer creates
for me I instantiate a new object of the component designer and set its
properties accordingly (mainly the SqlServer connection on the command
objects so that each Sql server command has its own connection).
>
One thing of note:
>
1.) Private methods are exposed to the New Instance of the component
designer inside of the static method. (Makes me a bit concerned that
something funny is going on)
>
The code below gives an example.
>
>
>
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Data.SqlClient;
>
namespace GoDAT.Venue
{
>
public class Venue : System.ComponentModel.Component
{
// ~~~~
// ~~~~
#region CONSTRUCTOR
public Venue(System.ComponentModel.IContainer container)
{
container.Add(this);
InitializeComponent();
}
public Venue()
{
InitializeComponent();
}
#endregion
// ~~~~
// ~~~~
>
// ~~~~
// ~~
#region DISPOSAL
protected override void Dispose( bool disposing )
{
//blah, blah, blah
}
#endregion
>
private System.Data.SqlClient.SqlCommand sqlSelect_Venue;
private System.Data.SqlClient.SqlCommand sqlInsert_Venue;
private System.Data.SqlClient.SqlCommand sqlUpdate_Venue;
private System.Data.SqlClient.SqlCommand sqlDelete_Venue;
private System.Data.SqlClient.SqlDataAdapter sqlDA_Venue;
private GoDAT.Venue.dsVenue dsVenue1;
// ~~~~~
// ~~~~~
>
// ~~~~
// ~~~~
#region Component Designer generated code
// ALL THAT GREAT CODE GENERATED FOR FREE!!!!
// Or rather for the price of VS.NET and the
// hours of trial and error trying to figure
// out how to best leverage it.
#endregion
// ~~~~
// ~~~~
>
// ~~~~
public static GoDAT.Venue.dsVenue Get_dsVenue()
{
>
Venue tmpThis = new Venue();
GoDAT.Venue.dsVenue tmpDS = tmpThis.dsVenue1;
SqlDataAdapter adapter = tmpThis.sqlDA_Venue;
>
tmpThis.sqlSelect_Venue.Connection = SQLConnMgr.GetSqlConn();
tmpThis.sqlSelect_Venue.Connection.Open();
try
{
adapter.Fill(tmpDS);
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(("[Get_dsVenue] Exception " +
e.Message));
}
finally
{
adapter.Dispose();
tmpThis.sqlSelect_Venue.Connection.Close();
tmpThis.sqlSelect_Venue.Connection = null;
tmpThis = null;
}
>
return tmpDS;
}
// ~~~~~
}
}
>


"Electric Co." <jmcphee@.ucalgary.cawrote in message
news:1155145846.449750.188470@.m79g2000cwm.googlegr oups.com...
You don't have to do what I suggested, you may been to weigh the pro's and
con's first before you do.

Quote:

Originally Posted by

Hello,
>
I am newbie to the group so hi all! My name is Jim and I am a
codaholic. Ok so now that is out of the way.
>
>
I am new to using all things static and I am wondering if what I am
doing is going to get me in trouble.
>
I am using the component designer to build my Sql Server objects for
me. I then expose methods such as getDataSet as static methods. In
order to leverage the non-static properties that the designer creates
for me I instantiate a new object of the component designer and set its
properties accordingly (mainly the SqlServer connection on the command
objects so that each Sql server command has its own connection).
>
One thing of note:
>
1.) Private methods are exposed to the New Instance of the component
designer inside of the static method. (Makes me a bit concerned that
something funny is going on)
>
The code below gives an example.
>
>
>
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Data.SqlClient;
>
namespace GoDAT.Venue
{
>
public class Venue : System.ComponentModel.Component
{
// ~~~~
// ~~~~
#region CONSTRUCTOR
public Venue(System.ComponentModel.IContainer container)
{
container.Add(this);
InitializeComponent();
}
public Venue()
{
InitializeComponent();
}
#endregion
// ~~~~
// ~~~~
>
// ~~~~
// ~~
#region DISPOSAL
protected override void Dispose( bool disposing )
{
//blah, blah, blah
}
#endregion
>
private System.Data.SqlClient.SqlCommand sqlSelect_Venue;
private System.Data.SqlClient.SqlCommand sqlInsert_Venue;
private System.Data.SqlClient.SqlCommand sqlUpdate_Venue;
private System.Data.SqlClient.SqlCommand sqlDelete_Venue;
private System.Data.SqlClient.SqlDataAdapter sqlDA_Venue;
private GoDAT.Venue.dsVenue dsVenue1;
// ~~~~~
// ~~~~~
>
// ~~~~
// ~~~~
#region Component Designer generated code
// ALL THAT GREAT CODE GENERATED FOR FREE!!!!
// Or rather for the price of VS.NET and the
// hours of trial and error trying to figure
// out how to best leverage it.
#endregion
// ~~~~
// ~~~~
>
// ~~~~
public static GoDAT.Venue.dsVenue Get_dsVenue()
{
>
Venue tmpThis = new Venue();
GoDAT.Venue.dsVenue tmpDS = tmpThis.dsVenue1;
SqlDataAdapter adapter = tmpThis.sqlDA_Venue;
>
tmpThis.sqlSelect_Venue.Connection = SQLConnMgr.GetSqlConn();
tmpThis.sqlSelect_Venue.Connection.Open();
try
{
adapter.Fill(tmpDS);
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(("[Get_dsVenue] Exception " +
e.Message));
}
finally
{
adapter.Dispose();
tmpThis.sqlSelect_Venue.Connection.Close();
tmpThis.sqlSelect_Venue.Connection = null;
tmpThis = null;
}
>
return tmpDS;
}
// ~~~~~
}
}
>


Hi,

Thanx, I thought your suggestion was brilliant.

Jim