Sunday, October 30, 2011

How to get web site url in asp.net


When you want to get one web site url such as http://www.iblogseeker.com/register.aspx, use the following code:
 
public string GetSiteUrl()
{
string baseUrl = null;
HttpContext c = HttpContext.Current;
if (c != null)
{
string port = c.Request.ServerVariables["SERVER_PORT"];
if (port == null || port.Equals("80") || port.Equals("443"))
port = String.Empty;
else
port = ":" + port;
string protocol = c.Request.ServerVariables["SERVER_PORT_SECURE"];
if (protocol == null || protocol.Equals("0"))
protocol = "http://";
else
protocol = "https://";
baseUrl = protocol + c.Request.ServerVariables["SERVER_NAME"] + port + c.Request.ApplicationPath;
}
return baseUrl;
}

It covers any url in active on web.

Monday, June 8, 2009

AdSense for domains

What is AdSense for domains?

AdSense for domains allows publishers with unused domains to help users reach relevant information by presenting content on the domains.

Users often type domains into their address bar or follow expired links leading to sites with no content. Instead of an "under construction" page or 404 error, AdSense for domains provides links, search results, advertisements and other content. To do this, we use semantic technology targeted to the domain name. You earn revenue when users interact with the ads on your site.

If you have a site that has content on it (e.g., articles, reviews, forums, blog postings or other text), then your site should be used with AdSense for content. If you have a page with no content on it, then AdSense for domains can help your users. To get started with AdSense for domains, check out our set-up instructions, or search or browse our AdSense Help Forum for more information.

AdSense for domains

Use the Google Chart API to create charts for your web applications

With the Google Chart API you can build a URL that will dynamically create a chart for you. This service is used internally for Google Finance, Google Video, and beyond. Now, anyone can use it!

Although it is simple to use (just a darn URL after all) you will see that there are many options.

Here is just a few charts to show how broad this is:

Line Chart

http://chart.apis.google.com/chart?cht=lxy&chs=200×125&chd=t:0,30,60,70,90,95,100|20,30,40,50,60,70,80|10,30,40,45,52|100,90,40,20,10|-1|5,33,50,55,7&chco=3072F3,ff0000,00aaaa&chls=2,4,1&chm=s,FF0000,0,-1,5|s,0000ff,1,-1,5|s,00aa00,2,-1,5

Bar Charts

http://chart.apis.google.com/chart?cht=bvg&chs=200×125&chd=s:hello,world&chco=cc0000,00aa00

Pie Charts

http://chart.apis.google.com/chart?cht=p3&chd=s:Uf9a&chs=200×100&chl=Rails|PHP|Java|.NET

Venn Diagrams

http://chart.apis.google.com/chart?cht=v&chs=200×100&chd=t:100,80,60,30,30,30,10

Scatter

http://chart.apis.google.com/chart?cht=s&chd=s:984sttvuvkQIBLKNCAIi,DEJPgq0uov17zwopQODS,AFLPTXaflptx159gsDrn&chxt=x,y&chxl=0:|0|2|3|4|5|6|7|8|9|10|1:|0|25|50|75|100&chs=200×125

Solid Fill

http://chart.apis.google.com/chart?cht=lc&chd=s:pqokeYONOMEBAKPOQVTXZdecaZcglprqxuux393ztpoonkeggjp&chco=FF0000&chls=4.0,3.0,0.0&chs=200×125&chxt=x,y&chxl=0:|Jun|July|Aug|1:||20|30|40|50&chf=bg,s,efefef

Wednesday, May 13, 2009

Turn the submit button off when it press in ASP.Net

Sometime, we need to turn the button off after user clicking to prevent the double actions. Let's say, when I developed 2C2P payment processor,  I have to disable the "Confirm" button to avoid the double payment transactions when user click the button once. Otherwise, we will have the complaint from user about duplicated transactions when user might click the button double times since page loading is slow (behind scene, it's processing). The following example show you that it turn the submit button off and show message when it press using server-side script.

Disable button after clicking

Here is button control to add <form> tag.
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" Width="97px" />

Put the following code to code-behind as below.
protected void Page_Load(object sender, EventArgs e)
{
            this.Button1.Attributes.Add("onclick", "this.value='Please wait...';this.disabled = true;"
                + Page.ClientScript.GetPostBackEventReference(this.Button1, ""));
}
protected void Button1_Click(object sender, EventArgs e)
{
            //Here go on for click event
}

Now, click the button every times, it disable itself and user don't have a chance to press the button double.


How to limit the text length as maximum with Javascript (Text Counter)

Here is the javascript text counter. When you write down the character in Textarea box, it show the available text count immediately and remove the extra text as well. Put the following javascript between <head> and </head> tag.
<script type="text/javascript">
function textCounter(field, countfield, maxlimit)
{
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
    else
        countfield.value = maxlimit - field.value.length;
}
</script>
Here is form tag.
<form>
<span>Comments:</span>
<span>Only 200 char allowed</span>
<textarea id="comment" onblur="this.style.backgroundColor='#ffffff'" onfocus="this.style.backgroundColor='#FFFCF9'" onkeyup="textCounter(comment,textCount,200);" onkeydown="textCounter(comment,textCount,200);" rows="7" cols="60" name="comment" style="background-color: rgb(255, 255, 255);">
</textarea>
<input type="text" value="200" maxlength="3" size="3" id="textCount" name="textCount"/>
<span>Char count</span>
</form>

That's it. Enjoy the JScript!