Showing posts with label sample. Show all posts
Showing posts with label sample. Show all posts

Wednesday, March 28, 2012

String.Formatting a javascript code sample, how do I escape the { } characters?

Hi,

I'm trying to String.format a piece of javascript code

string.Format("function showalert(msg) { window.status = '{0}'; alert(msg); }", "Test");

This compiles ok but when it runs it has a Input string was not in a correct format exception as the '{' and '}' characters are reserved and used for substitution in the string.Format function.

Is there a way I can escape the '{}' characters so that the string.format function ignores them?

I've tried

string.Format("function showalert(msg) \{ window.status = '{0}'; alert(msg); \}", "Test");

which is normally how you escape but it dosen't work.

Thanks for your help

Auschucky

Hi ,To specify a single literal brace character informat, specify two leading or trailing brace characters; that is, "{{" or "}}".
string test =string.Format("function showalert(msg) {{ window.status = '{0}'; alert(msg); }}","Test");
Hope this helps , Gook Luck^_^
Ta, worked a treat

Thursday, March 22, 2012

structure

Muhammad,

James' sample is great, you might also want to take a look at an
article I put together a while ago on the subject: -

http://aspalliance.com/431

Hth,
Phil Winstanley
Microsoft ASP.NET MVP
http://www.myservicescentral.comthat is extremely helpful. thank you phil.

"Phil Winstanley [Microsoft MVP ASP.NET]" <phil@.winstanley.name> wrote in
message news:camn5j$65l@.odak26.prod.google.com...
> Muhammad,
> James' sample is great, you might also want to take a look at an
> article I put together a while ago on the subject: -
> http://aspalliance.com/431
> Hth,
> Phil Winstanley
> Microsoft ASP.NET MVP
> http://www.myservicescentral.com

Tuesday, March 13, 2012

Stuck on loading pages into a placeholder

Hi Folks,

Can someone point me to a sample or tutorial or the code to load pages into a placeholder.

I have a menu bar on the left of the page and am trying to load the clicked pages on the right.

Any ideas,

Cheers
NickWelcome to the ASP.NET forums, Nick.

You may be very interested inUser Controls. (They were originally called Pagelets, since they are very much like you described ... littles pages that you embed within your main page.)

That link is one of theQuickStart Tutorials which you might want to look through.

Hope this helps.
Hmm ive had a read over and im still stuck.

do i include the code in a script block or in the codebehind file??
Umm, neither.

Can you show the code for your page, indicating which part you want to separate out as the menu bar, and which page will have the content loaded into it?

If you do so, can you please post it between<code> and</code> tags?
Here it is.


for the link
<TD>
<a id="goHome" runat="server"><img src="http://pics.10026.com/?src=images/myWebHome.jpg"></a>
</TD>
with goHome.HRef defined in the cs file.

<TABLE cellSpacing="10" cellPadding="0" width="100%" border="0">
<asp:placeholder id="PageBody" runat="server"></asp:placeholder>
</TABLE>

I'm trying to get the link to display in the placeholder.
Cheers,
Nick
Why not use frames?
One more question before I can show you an answer.

When you say you are trying to load "pages" into a Placeholder, do you mean anentire webpage inside the table cell? Or do you just want to load differentcontent into the table cell, based on the button the user has clicked?
At the moment it is content contained within an aspx file, so an entire page I guess, what other options are available. I'm a bit of a noob to all this and have to get myself on a steep learning curve. Thanks for all your help and time.
You should really be putting yoursections of content in a User Control (.ascx), Loading them (using Page.LoadControl) when appropriate and then adding them to the PlaceHolder Control. For example:

 void Page_Load ( Object src, EventArgs eArgs ) {

Control page;

switch ( QueryString [ "page" ] ) {

case "Home" : page = LoadControl ( "/controls/home.ascx" );
break;
case "About" : page = LoadControl ( "/controls/about.ascx" );
break;
...
}

PageBody.Controls.Add ( page );
}


I assume this goes into a <script> block in the actual page. Now how do I pass the param to the switch?
Either in a <script> declaration block or CodeBehind.

The requesting URL would look like:

 http://www.domain.com/default.aspx?page=Home