Showing posts with label void. Show all posts
Showing posts with label void. Show all posts

Wednesday, March 28, 2012

String.Format("{0:p}" - - Remove that space?

Ok this may be silly but I have to ask. Short of doing this:
protected void Page_Load(object sender, EventArgs e) { Single s = 0.0241F; Literal1.Text = String.Format("{0:p}", s).Replace(" %","%"); }

Is there any other way to remove the space between the number and the % sign?

Just Curious.

I do not think so. If exists, please let me know.

This works:

CultureInfo ci=CultureInfo.CurrentCulture.Clone()

as CultureInfo;

System.Threading.Thread.CurrentThread.CurrentCulture=ci;

ci.NumberFormat.PercentNegativePattern=1;

ci.NumberFormat.PercentPositivePattern=1;

int x=5,y=-5;

Response.Write(String.Format("{0:p} {1:p}",x,y));


Yeah work well. Can that be done in WebConfig?
This thread was great, both with the Replace and Culture methods! Thank you, both.
I would think you could set the culture when the web page loaded. Then in the Web.Config you could set the ci.NumberFormat.PercentPositivePattern=1.

Thursday, March 22, 2012

Strongly Type Web Forms

How does a User Control invoke a method on its parent page? Say I have a publicMethod in code behind for an aspx page:
...
public void SomeImportantMethod() { /* do important stuff */}
...
From an Event Handler within the User Control, I'd like to invoke a method on the page in which the User Control is embedded. If I stop in the debugger and inspect this.Page, I see that it has a type of "ASP.MyAspxPage"... where did that come from? Can I delcare it intentionally somewhere?
TIA,
Geo
Your MyAspxPage is your custom page class, which inherits from the System.Web.UI.Page class.
The thing with UserControls is though, that you don't know what parent page they could be in at run-time.
So, to be safe, if you want to call a particular method on the parentPage, I'd say let your Page implement your interface which contains themethod signature (and other stuff if you want).
In your UserControl you then do a defensive cast (using the as keyword)to that interface and check for != null. You then simply call yourmethod on your interface object.
Hope that helps.
Wim

Yes, that does help. It helped in that I was hung up in anold paradigm and should get over it and just use an interface. So, thanks, that helped me get the job done.
I guess I was stuck in theOLD ASP.NET 1.1 code behind days where an ASPX page would have a code behind page which had a namespace declaration and the web form would be a public class derived from System.Web.UI.Page. So, from any C# code I could say:
MyNamespace.MyPage myPage = this.Page as MyNameSpace.MyPage;
if ( myPage != null)
{
myPage.MyMethod("hello world");
}
else
{
Response.Write("what gives?");
}
No fuss no muss, no interfaces.
I think I better go find an article or 2 on code beside or what ever it is we call it now.
Thanks again,
geo

Hello.

I think that you can also use the @.reference directive to introduce the type of the page in the user control (haven't tried it though).

Tuesday, March 13, 2012

Struggling - 'static' vs 'void' etc?

I am really struggling to conceptually understand classes in C# especially
the use of the strange keywords 'static' 'void' and 'override'...
Is there a 'idiots' way of understanding these concepts broadly before even
touching a line of code...
Thanks
JasonGoogle: "C# Class Design"
WROX "C# Class Design - Coding Effective Classes Handbook" is what you need.
<%= Clinton Gallagher
METROmilwaukee "Regional Information Services"
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
<jason@.catamaranco.com> wrote in message
news:eawJ2zs6EHA.1260@.TK2MSFTNGP12.phx.gbl...
> I am really struggling to conceptually understand classes in C# especially
> the use of the strange keywords 'static' 'void' and 'override'...
> Is there a 'idiots' way of understanding these concepts broadly before
even
> touching a line of code...
>
> Thanks
> Jason
>
Static = non-object
Void = a method that does not return a value
Override = when you decide to discard the origins and implenet your own.
The better definitions can be viewed here:
http://msdn.microsoft.com/library/d...keywords_pg.asp
John
<jason@.catamaranco.com> wrote in message
news:eawJ2zs6EHA.1260@.TK2MSFTNGP12.phx.gbl...
>I am really struggling to conceptually understand classes in C# especially
> the use of the strange keywords 'static' 'void' and 'override'...
> Is there a 'idiots' way of understanding these concepts broadly before
> even
> touching a line of code...
>
> Thanks
> Jason
>
This should help get you started.
http://www.geocities.com/jeff_louie/oop.htm
Regards,
Jeff
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
Thanks guys...!
<jason@.catamaranco.com> wrote in message
news:eawJ2zs6EHA.1260@.TK2MSFTNGP12.phx.gbl...
> I am really struggling to conceptually understand classes in C# especially
> the use of the strange keywords 'static' 'void' and 'override'...
> Is there a 'idiots' way of understanding these concepts broadly before
even
> touching a line of code...
>
> Thanks
> Jason
>

Struggling - static vs void etc?

I am really struggling to conceptually understand classes in C# especially
the use of the strange keywords 'static' 'void' and 'override'...

Is there a 'idiots' way of understanding these concepts broadly before even
touching a line of code...

Thanks
JasonGoogle: "C# Class Design"
WROX "C# Class Design - Coding Effective Classes Handbook" is what you need.

--
<%= Clinton Gallagher
METROmilwaukee "Regional Information Services"
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/

<jason@.catamaranco.com> wrote in message
news:eawJ2zs6EHA.1260@.TK2MSFTNGP12.phx.gbl...
> I am really struggling to conceptually understand classes in C# especially
> the use of the strange keywords 'static' 'void' and 'override'...
> Is there a 'idiots' way of understanding these concepts broadly before
even
> touching a line of code...
>
> Thanks
> Jason
Static = non-object
Void = a method that does not return a value
Override = when you decide to discard the origins and implenet your own.

The better definitions can be viewed here:
http://msdn.microsoft.com/library/d...keywords_pg.asp

John

<jason@.catamaranco.com> wrote in message
news:eawJ2zs6EHA.1260@.TK2MSFTNGP12.phx.gbl...
>I am really struggling to conceptually understand classes in C# especially
> the use of the strange keywords 'static' 'void' and 'override'...
> Is there a 'idiots' way of understanding these concepts broadly before
> even
> touching a line of code...
>
> Thanks
> Jason
This should help get you started.

http://www.geocities.com/jeff_louie/oop.htm

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Thanks guys...!
<jason@.catamaranco.com> wrote in message
news:eawJ2zs6EHA.1260@.TK2MSFTNGP12.phx.gbl...
> I am really struggling to conceptually understand classes in C# especially
> the use of the strange keywords 'static' 'void' and 'override'...
> Is there a 'idiots' way of understanding these concepts broadly before
even
> touching a line of code...
>
> Thanks
> Jason
I found this sample chapter on C# extremly helpful...as a newbie I have
been searching for a 'magic' way to instantly digesting the 'broad' concepts
in C# this tutorial helped me a lot:

http://www.joegrip.com/csharp-course.html (see flash C#)

- Jason
<jason@.catamaranco.com> wrote in message
news:eawJ2zs6EHA.1260@.TK2MSFTNGP12.phx.gbl...
> I am really struggling to conceptually understand classes in C# especially
> the use of the strange keywords 'static' 'void' and 'override'...
> Is there a 'idiots' way of understanding these concepts broadly before
even
> touching a line of code...
>
> Thanks
> Jason