Asp.Net Server Side: How to get Iframe’s Parent Window Url?

In Asp.Net server sided button’s click event, I somehow needed to find parent window url of an iframe, which means the url you see in the address bar of your web browser.

Let’s think of 2 pages: Parent.aspx and Child.aspx. Child.aspx is loading to an iframe in Parent.aspx. If you have a button in Child.aspx, you will be getting “Child.aspx” result when you use Request.Url method in this button’s click event.

But you see “Parent.aspx” in the address bar, right? So how to get it?

Here you need to work with client side peacefully. Otherwise the server will keep giving you the same result.

First, place a button running at server, add a click event and a client-click event.

    <asp:Button ID="btnFindParentUrl" runat="server" Text="Get Url!" OnClick="btnFindParentUrl_Click" OnClientClick="fillHidden();"></asp:Button>

Put a hidden textbox inside a div with style=”display: none;” (not Visible=”false” for button because if you do client can’t see and fill it):

    <div style="display: none;">
        <asp:TextBox ID="txtHiddenUrlField" runat="server" BorderStyle="None" Font-Size="0px" ForeColor="#F6F6F6" Height="0px" Width="0px"></asp:TextBox>

Now place javascript code of fillHidden() function:

    <script type="text/javascript">
        function fillHidden() {
            document.getElementById('<%= txtHiddenUrlField.ClientID %>').value = parent.document.location.href;

That’s all you have to do at client side.
Let’s go to the server:

    protected void btnFindParentUrl_Click(object sender, EventArgs e)
        string parentUrl = txtHiddenUrlField.Text;

This way, you should be getting parent url from button in an iframe.


T-SQL: How to Order by Surname in Full Name Column?

Sometimes you need to do ordering by in a full name column. If you want to order by first name, that’s cool, but when you need to order by last name, you need to find the surname for each field.

Let’s take a look at this data:

[Full Name]
Albert Einstein
Leonardo da Vinci
Nicolas Tesla

These values are ordered by first name so there’s no problem with that. But if we wanted to order by last name(which is not a particular column in this table), we had to find a way like splitting these fields or something else.

Anyway, there was a good line of code in StackOverflow (see question&answer here) written by user Recep.

SELECT [Full Name], REVERSE(SUBSTRING(REVERSE([Full Name]), 0, CHARINDEX(' ', REVERSE([Full Name])))) AS SurnameAfterReversing
--We need to select our ORDER BY expression as a new column otherwise it will warn that it can't order by a column which is not exist in query result.

It reverses the whole name here, then gets text until the first space (‘ ‘) character, then reverses the new text back. That way, we actually get the last name so you can do anything you want with this column.

And here is the data as a result of this query:

[Full Name] SurnameAfterReversing
—————————- —————————-
Albert Einstein Einstein
Nicolas Tesla Tesla
Leonardo da Vinci Vinci
1 Comment

iOS 6 is Still Beta

iOS 6

The ones who involved with iOS or iOS development might have heard about the beta version of iOS 6. It’s only open for registered Apple developers at the moment but I assure you it’s better this way. People expecting Apple to release latest and common version in fall 2012.

If you want to take a look at new features, here’s 2 links:
One is in English: Link [Eng],
Another is in Turkish:  #iPhoneTurkey Link [Tr]

Since I am registered as a developer, I had a chance to try iOS 6 beta in my iPhone 4S.

Before I start, I also downloaded the new beta version of Xcode 4.5 and I tried to upgrade through it. But I had the “The iPhone “xxx” could not be updated. This device isn’t eligible for the requested build.” error. I did what adviced on some websites but it didn’t change the result. Then I tried to upgrade through iTunes (which I guess the supported way) and it was successfully done.

I was be able to restore my data but I forgot to sync the apps so all of them was lost. I had to go to my history in App Store and redownload all. Luckily, my restore data had all the data of applications so I lost no data.

As you see, if you want to upgrade, you better not try Xcode instead of iTunes and don’t forget to backup your iPhone then sync all the apps.

What I saw at first that my iPhone was struggling to run iOS 6 sometimes, it was ending up burning like hell. It wasn’t happening all the time actually but for certain applications.

For example, iOS 6 mail application was running too slow sometimes and it doesn’t even respond. Then the iPhone’s temperature was getting high quickly.

Also, since Apple will be using its own maps application instead of Google Maps, the Map application is working on Apple Maps. I wasn’t sure about what the problem is but the maps application is totally useless at the moment. I guess my location Turkiye is involved with this issue but maps application is very slow and it doesn’t even show the maps. They added voice navigation and 3D view too but I couldn’t even get there since the maps app was not working stabile. It also caused heat problem, too.

For sure, beta version had pretty cool features which you will get a chance to see in the links I shared above. What I liked that Siri could open applications now [in iOS 5, it says “I’d like to but I’m not allowed to :(“] and navigation in maps will save most people buying a navigation app (I might be one of those), you have options for incoming calls like reply with an sms etc., you can set your iPhone to “don’t disturb” mode or you can keep it open for chosen contacts and all that kind of stuff.

But even though I’m an Apple Developer, I think I’ll wait for the community version of iOS 6. If they release fixed version of beta, that will stay as an option too.

Post a comment

Generate Random Number and String in MS SQL Server

Sometimes you might wanna generate random number or string in MS SQL. For example, I do it for temporary user passwords.

Here’s how you generate a random number. X is the max value, the code is generating between 0 and (X-1).


Be aware that max. generated number is X-1 because it’s generating X numbers starting from 0(zero).

If you generate 5 numbers, your range will be: {0, 1, 2, 3, 4}.


Another code is generating random string(VARCHAR). Here it is:

SELECT SUBSTRING(CONVERT(varchar(255), NEWID()), 0, 9)

Attention to 0, 9. It’s substring range, here I’m generating a string value whose length is 10 characters.

1 Comment