Monday, May 25, 2009

Running a SQL query to replace certain characters in a table

Let say,
You have a database that contains many characters and symbols. If you want to replace those , just run the following SQL query:

(Here, suppose a symbol ~! need to replace by - then your query will be:)

UPDATE table
SET ColumnName= replace(LTRIM(RTRIM(ColumnName)), '~!', '-')

Happy Programming!:)

Sunday, May 10, 2009

Master page with Searchbox

Consider a master page with a search functionality and other number of content pages derived from that master page, so that searchbox appears in all pages. If you want to display a search results in Search.aspx page no matter where you are( in other content pages),add this code:

In MasterPage.cs:
Protected void search_button_Click(object sender, EventArgs e)
{
//redirect textbox's value to search.aspx page
Response.Redirect(@"~/search.aspx?q=" + Server.UrlEncode(txtSearch.Text));
}

In Search.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
//read the master page's redirected value
string str = Request.QueryString[@"q"];
}

--Happy Coding

Wednesday, April 15, 2009

Disable Browser Back Button

If you want to disable going back in the previous page, I am going to show you very easy method to do this:

Suppose you are in Page 1 and go to page 2. If you want to go back to page 1 , you are able to go. But now, if you want to disable that going back features, add the following script in the body tag of the page 1:

body onload=”if(history.length>0)history.go(+1);”

This works only for IE and not for Mozilla Firefox. For Mozilla do this:

add this script within head:

function noBack()
{
window.history.forward()
}
noBack();
window.onload=noBack;
window.onpageshow=function(evt)
{
if(evt.persisted)noBack()
}
window.onunload=function()
{
void(0)
}

It works not only with Firefox but also with IE, Safari, Opera.

Sunday, March 15, 2009

Close the popup image when click on it

To close the popped up image when click on , do the following steps:

Create ShowImage.aspx page and add a image control with onclick property like:

asp:Image ID="Image1" runat="server" onclick = "window.open('','_self');window.close();"

And in the page load of ShowImage.aspx do this way:

if (Request.QueryString["image"] != null)
{
Image1.ImageUrl = Request.QueryString["image"];
}

Now, on the parent page write this script:

var Popup;
function popUp(url)
{
Popup = window.open(url, "Popup", 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=100,height=100,left = 490,top = 262');
Popup.focus();
}
function ChangeImg(obj)
{
//Show in popup
var radio = obj.getElementsByTagName("input");
for (var i=0;i less than radio.length;i++)
{
if (radio[i].checked)
{
popUp("ShowImage.aspx?image=images/" + radio[i].value + ".jpg");
}
}
}

Note: Use the general sign for 'Less than' in the for loop. I am unable to publish here because it acts like HTML tags and won't let me go.