Well last week I had to quickly redevelop the web forms I developed to implement no postbacks. The forms we are developing has several fields and to do a post back on each one would slow the webpages down. So the solution was simple enough of switching out asp image button with a old style html input button. Now we can open a new window without postback and send back information into a textbox field with out any slow downs.
P.S. I have a complaint about about browsers and W3C, to center a page you have to use the attribute "style" with the left and right width to auto. The thing is that this doesn't work in the browsers (IE and Firefox). So while in VS 2005 I made a div tag with the attribute 'align' sent to center, but this of course gives a warning that this technique is out dated. WTF?!?!?!?!?!?!?!?!?!
Interesting programming ideas, solutions, and logic that I have used to solve problems or have come across throughout my career.
About Me
- William Andrus
- Northglenn, Colorado, United States
- I'm primarily a BI Developer on the Microsoft stack. I do sometimes touch upon other Microsoft stacks ( web development, application development, and sql server development).
Sunday, May 21, 2006
Saturday, May 13, 2006
Web Controls and Pop Up Windows with ASP.Net 2.0
One of the first web controls that we developed with good reusability is a web control that pops up another window. This doesn't seem much, but does give more posibilites of what can then be done on the newly open window.
Well, to have a pop up window, we developed a image button, which can be used and is more user friendly. We also wanted to make it more possible to change the size of the pop up window.
private System.Web.UI.WebControls.ImageButton _imageBtn; //Button with image used to call pop-up page
private System.String _popUpLoc; //Location of the popup page
private System.Web.UI.WebControls.Unit _popUpPageWidth; //Width of the pop up page
private System.Web.UI.WebControls.Unit _popUpPageHeight; //Height of the pop up page
Next are the properties so we can change values during the design view. Most of which are obvious, so here is an example of one:
[Bindable(true)]//used for binding
[Category("Pop Up Window")] //in properties section "Pop Up Window"
[Description("The URL of the pop-up webpage")]//description of PagePopUp
[DefaultValue("")]//default value
[Localizable(true)]//allow multi-language
public virtual System.String PopUpURL
{
get
{
return this._popUpLoc; //returns a string representing the location of the image
}
set
{
this._popUpLoc = value; //set the string value for the location of the image button
}
}
etc... for the other properties you might want to set. Use EnsureChildControls(); for controls that are used on the page.
Next override the CreateChildControls:
protected override void CreateChildControls()
{
Controls.Clear(); //clear the controls before adding them
this._imageBtn = new System.Web.UI.WebControls.ImageButton();//declare image button with image on it
this._imageBtn.ID = "CalendarBtn";//set the id of the image button
Controls.Add(this._imageBtn);//add the image button to the child control collection
}
In the render control is where we add an attribute to the image button.
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
AddAttributesToRender(writer); //add HTML that needs to be render
/*
* Calls javascript to open a new window and send in the text box id
*
* this.PopUpURL is the page to pop open
* this.Page.Form.ClientID represents the page's form id eg:
* this.ClientID represents the web controls's ID eg:
* the height and width variables are used to set the dimensions of the browser
* the status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no are used to remove usless items and fixate the window size
*
* Note: since during the page initialization the controls are developed before the page
* we had to place the _imageBtn.Attributes.Add(...) into the render method
* to prevent NullException error.
*
*/
_imageBtn.Attributes.Add("onclick", "window.open('" + this._popUpLoc
+ "?field=" + this.Page.Form.ClientID + "." + this.ClientID
+ "',null,'height=" + this._popUpPageHeight + ", width="
+ this._popUpPageWidth + ",status= no, resizable= no, scrollbars=no, toolbar=no, location=no, menubar=no ');");
this._imageBtn.RenderControl(writer);//render the image button
}
Well, to have a pop up window, we developed a image button, which can be used and is more user friendly. We also wanted to make it more possible to change the size of the pop up window.
private System.Web.UI.WebControls.ImageButton _imageBtn; //Button with image used to call pop-up page
private System.String _popUpLoc; //Location of the popup page
private System.Web.UI.WebControls.Unit _popUpPageWidth; //Width of the pop up page
private System.Web.UI.WebControls.Unit _popUpPageHeight; //Height of the pop up page
Next are the properties so we can change values during the design view. Most of which are obvious, so here is an example of one:
[Bindable(true)]//used for binding
[Category("Pop Up Window")] //in properties section "Pop Up Window"
[Description("The URL of the pop-up webpage")]//description of PagePopUp
[DefaultValue("")]//default value
[Localizable(true)]//allow multi-language
public virtual System.String PopUpURL
{
get
{
return this._popUpLoc; //returns a string representing the location of the image
}
set
{
this._popUpLoc = value; //set the string value for the location of the image button
}
}
etc... for the other properties you might want to set. Use EnsureChildControls(); for controls that are used on the page.
Next override the CreateChildControls:
protected override void CreateChildControls()
{
Controls.Clear(); //clear the controls before adding them
this._imageBtn = new System.Web.UI.WebControls.ImageButton();//declare image button with image on it
this._imageBtn.ID = "CalendarBtn";//set the id of the image button
Controls.Add(this._imageBtn);//add the image button to the child control collection
}
In the render control is where we add an attribute to the image button.
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
AddAttributesToRender(writer); //add HTML that needs to be render
/*
* Calls javascript to open a new window and send in the text box id
*
* this.PopUpURL is the page to pop open
* this.Page.Form.ClientID represents the page's form id eg:
* this.ClientID represents the web controls's ID eg:
* the height and width variables are used to set the dimensions of the browser
* the status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no are used to remove usless items and fixate the window size
*
* Note: since during the page initialization the controls are developed before the page
* we had to place the _imageBtn.Attributes.Add(...) into the render method
* to prevent NullException error.
*
*/
_imageBtn.Attributes.Add("onclick", "window.open('" + this._popUpLoc
+ "?field=" + this.Page.Form.ClientID + "." + this.ClientID
+ "',null,'height=" + this._popUpPageHeight + ", width="
+ this._popUpPageWidth + ",status= no, resizable= no, scrollbars=no, toolbar=no, location=no, menubar=no ');");
this._imageBtn.RenderControl(writer);//render the image button
}
Tuesday, May 09, 2006
How To: Run Web Control next to an application during development
So here at work, we are trying to get some web controls to work with pop-up windows. Here is a nice easy way to set up your test envirnoment.
Create a new website for testing. Eg. WebControlTester.
within the Solution Explorer place your web control into a new folder App_Code
then add a web.config file to the Solution Explorer.
Within the web.config file add:
<pages>
<controls>
<add namespace="Your.Namespace.In.WebControl" tagprefix="SomeTagPrefix">
</controls>
</pages>
Now you can edit your web control, build it and then switch to the web site and run it.
<^_^>
Create a new website for testing. Eg. WebControlTester.
within the Solution Explorer place your web control into a new folder App_Code
then add a web.config file to the Solution Explorer.
Within the web.config file add:
<pages>
<controls>
<add namespace="Your.Namespace.In.WebControl" tagprefix="SomeTagPrefix">
</controls>
</pages>
Now you can edit your web control, build it and then switch to the web site and run it.
<^_^>
Friday, April 14, 2006
Krugle
So today, I got my Krugle beta test access. The not beta website, where you can read up on Krugle is: http://www.krugle.com/. Krugle is a search engine that you can use to search, view open source code, comment on, etc..
Well, the first thing I tried was C# to see if there was any, unfortunately there wasn't any.
So the next search I did, was on "reinforcment learning", and there were some code. I am pleased about this. I selected a source code called: test_agents.c
I am able to see the source code, the comments, etc. It is very nice to see how other programmers would do things.
I also took a look at a java class called RLPolicy.java, it was cool to see they implemented some of the exact same things I did.
They allow you to view the whole project, in which they catagorized the files to where they belong.
I'll probably look at some of the code, and if I find something I like, I'll probably rewrite it in C#, not to hard coming from code like C,C++, or Java.
Well, the first thing I tried was C# to see if there was any, unfortunately there wasn't any.
So the next search I did, was on "reinforcment learning", and there were some code. I am pleased about this. I selected a source code called: test_agents.c
I am able to see the source code, the comments, etc. It is very nice to see how other programmers would do things.
I also took a look at a java class called RLPolicy.java, it was cool to see they implemented some of the exact same things I did.
They allow you to view the whole project, in which they catagorized the files to where they belong.
I'll probably look at some of the code, and if I find something I like, I'll probably rewrite it in C#, not to hard coming from code like C,C++, or Java.
Tuesday, April 11, 2006
Old, but new to me: C# will this compile?
From: http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx
using System;
using System.Threading;
public class Class1
{
public static void Main ()
{
new Thread(delegate
{
Console.WriteLine("On another thread");
}).Start();
}
}
I couldn't see why it could ever worked, but then looking at his solutions http://blogs.msdn.com/brada/archive/2004/12/27/332863.aspx
I see why I didn't like it. I would have used the first version of his solution:
new Thread(
delegate ()
{
Console.WriteLine("On another thread");
}
).Start();
since it looks like the way a delegate would be initialized and a function that a thread would call.
using System;
using System.Threading;
public class Class1
{
public static void Main ()
{
new Thread(delegate
{
Console.WriteLine("On another thread");
}).Start();
}
}
I couldn't see why it could ever worked, but then looking at his solutions http://blogs.msdn.com/brada/archive/2004/12/27/332863.aspx
I see why I didn't like it. I would have used the first version of his solution:
new Thread(
delegate ()
{
Console.WriteLine("On another thread");
}
).Start();
since it looks like the way a delegate would be initialized and a function that a thread would call.
Monday, April 10, 2006
How To: Build a RPG in a week
http://www.gamedev.net/reference/articles/article2259.asp
Nice to see that an 80's RPG can easily be made with free tools. He did his programming with python, which is interesting to see that python has come a long way.
Nice to see that an 80's RPG can easily be made with free tools. He did his programming with python, which is interesting to see that python has come a long way.
Friday, April 07, 2006
How to pull an all nighter... (Shout out to Cornell)
http://www.christianmontoya.com/2006/04/04/how-to-pull-an-all-nighter/
Good basic tips:
Drink caffene, but not too much.
Eat food
Take a shower
Loud Music (doesn't work for me, makes me tired)
Walk around (any good exercise, like 20 pushups or something)
Don't lie down
Don't eat fatty food, I would also add sugary foods since they make you drowsy after 15 minutes
Don't turn the lights out (hope you don't have a room mate)
I never did an all nighter, but I also never procastinated. I knew the sooner I got my shit done, the more time I had to play Counter Strike. :)
Good basic tips:
Drink caffene, but not too much.
Eat food
Take a shower
Loud Music (doesn't work for me, makes me tired)
Walk around (any good exercise, like 20 pushups or something)
Don't lie down
Don't eat fatty food, I would also add sugary foods since they make you drowsy after 15 minutes
Don't turn the lights out (hope you don't have a room mate)
I never did an all nighter, but I also never procastinated. I knew the sooner I got my shit done, the more time I had to play Counter Strike. :)
Friday, March 24, 2006
Updated: AIM Plugin: SignOff
I just updated the program again, this time I added a better looking graphics to mimic the AIM Triton look, and I have also added the possibility of using sound (only WAV) to make a noise for notification.
http://williamandrus.tripod.com/AIMPlugin.html
Here is some of the code used to play WAV files in C#, in which I think I stole from some other website, a while back.
Well you will need this:
using System.Runtime.InteropServices;
Import a dll to play the WAV sound
[DllImport("winmm.dll")]
private static extern bool PlaySound(string lpszName, int hModule, int dwFlags);
Here is the enumeration of the SND
public enum SND
{
SND_SYNC = 0x0000 ,/* play synchronously (default) */
SND_ASYNC = 0x0001 , /* play asynchronously */
SND_NODEFAULT = 0x0002 , /* silence (!default) if sound not found */
SND_MEMORY = 0x0004 , /* pszSound points to a memory file */
SND_LOOP = 0x0008 , /* loop the sound until next sndPlaySound */
SND_NOSTOP = 0x0010 , /* don't stop any currently playing sound */
SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
SND_ALIAS = 0x00010000 ,/* name is a registry alias */
SND_ALIAS_ID = 0x00110000, /* alias is a pre d ID */
SND_FILENAME = 0x00020000, /* name is file name */
SND_RESOURCE = 0x00040004, /* name is resource name or atom */
SND_PURGE = 0x0040, /* purge non-static events for task */
SND_APPLICATION = 0x0080 /* look for application specific association */
}
Use this to play the WAV file:
PlaySound(fileName,0,1);
http://williamandrus.tripod.com/AIMPlugin.html
Here is some of the code used to play WAV files in C#, in which I think I stole from some other website, a while back.
Well you will need this:
using System.Runtime.InteropServices;
Import a dll to play the WAV sound
[DllImport("winmm.dll")]
private static extern bool PlaySound(string lpszName, int hModule, int dwFlags);
Here is the enumeration of the SND
public enum SND
{
SND_SYNC = 0x0000 ,/* play synchronously (default) */
SND_ASYNC = 0x0001 , /* play asynchronously */
SND_NODEFAULT = 0x0002 , /* silence (!default) if sound not found */
SND_MEMORY = 0x0004 , /* pszSound points to a memory file */
SND_LOOP = 0x0008 , /* loop the sound until next sndPlaySound */
SND_NOSTOP = 0x0010 , /* don't stop any currently playing sound */
SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
SND_ALIAS = 0x00010000 ,/* name is a registry alias */
SND_ALIAS_ID = 0x00110000, /* alias is a pre d ID */
SND_FILENAME = 0x00020000, /* name is file name */
SND_RESOURCE = 0x00040004, /* name is resource name or atom */
SND_PURGE = 0x0040, /* purge non-static events for task */
SND_APPLICATION = 0x0080 /* look for application specific association */
}
Use this to play the WAV file:
PlaySound(fileName,0,1);
Thursday, March 23, 2006
AIM Plugin: Sign Off Timer
So this is my first AIM Plugin ever developed, yeah me.
It basically allows the user to set how many minutes he/she would like to stay online. When this time is reached, a pop-up box is displayed and you are signed off. I remember when I was a college student, and I would be almost late for class because I was on AIM losing track of time.
Here is the website where you can download it: http://williamandrus.tripod.com/AIMPlugin.html
I set it up so that the timer would run on it's own thread, that way it won't interfere with the AIM's thread. So in the Exec function I have this little sniplet:
this then calls my function called StartTimer:
this then starts up another file which I used to make the form. Here is a sniplet from that program:
It basically allows the user to set how many minutes he/she would like to stay online. When this time is reached, a pop-up box is displayed and you are signed off. I remember when I was a college student, and I would be almost late for class because I was on AIM losing track of time.
Here is the website where you can download it: http://williamandrus.tripod.com/AIMPlugin.html
I set it up so that the timer would run on it's own thread, that way it won't interfere with the AIM's thread. So in the Exec function I have this little sniplet:
if(command == kCommandId)
{
Thread t = new Thread((new
ThreadStart(StartTimer)));
t.Start();
}
this then calls my function called StartTimer:
public void StartTimer()
{
TimeSelect timer = new TimeSelect(m_session);
timer.ShowDialog();
}
this then starts up another file which I used to make the form. Here is a sniplet from that program:
private void buttonOK_Click(object sender, System.EventArgs e)
{
CountDown = Convert.ToInt32(this.numericUpDownMinutes.Value);
this.Visible = false;
while(CountDown != 0)
{
Application.DoEvents();
}
MessageBox.Show("You haved been signed off
by the timer.","Sign Off Timer");
this.session.SignOff();
}
private void timeKeeper_Tick(object sender, EventArgs e)
{
if(sender == this.timeKeeper)
{
this.CountDown--;
}
}
Monday, March 20, 2006
AIM SDK
Well, I just started using the AIM SDK and I'm trying to develop and learn about using plugins for AIM. http://developer.aim.com/pluginMain.jsp
Once I have become more confortable with this, I might develop a simple program and build up from there. I would like to see if I could somehow use Google Map's API with AIM's API and see what I could put together in the future.
Once I have become more confortable with this, I might develop a simple program and build up from there. I would like to see if I could somehow use Google Map's API with AIM's API and see what I could put together in the future.
Subscribe to:
Posts (Atom)