Thomas’ Developer Blog

March 11, 2008

Passing ClientIDs from Parent to Child

Filed under: AJAX, Asp.Net Framework 2.0, javascript, vb.net — Tags: , , , , , — sanzon @ 5:07 am

Alright this is going to be a very basic post, but at least it’s an easy solution and it’s very clean. 

 Here is the problem.  You have a website that uses “AJAX” to upload images to the site.  If you know AJAX you can’t do that, instead we use an iframe, but despite that it’s generally the same concept of wanting to not have the main page refresh everytime.

The problem is once the image is uploaded you may want to store the image into a pool so that it can be checked and then added to into another folder once a database entry is included.  Basically…

You want to add a new user, but that user does not have an ID yet, so you have to create a temp folder to hold the image and then call that image name again so that it can get that image again and put it in the proper location once you have created the new record the user now have a legit userID.

So basically we just need to send the ID from the child to parent!  Easy!… at least with first thought.  You forget you have to use ClientID for Asp.net code!  Big problem, since you have to find a way of passing that ID to the child so it knows where to store the Image ID on the parent window.  To do this, simply create a querystring at the end of the iframe src.

You then can use javascript to get the querystring using: window.location.search.substring(1)

In this case I only have it as url.aspx?ClientID

If you have several items in a querystring you’ll have to use a split function, which you can just google to find a lot of results. 

Well now that you have the clientID in the querystring you can access it with javascript, use getElementById and then store the information into the parent window!  Easy!

The other two methods include storing the clientID in a session variable… ok solution.. but it waste memory.  The other is to use parent child relationships! @_@…  basically you use a standard HTML DOM ID for a div and store the hidden input within the div and search it by using parent child relatinoships… TOO MUCH CODE!  So generally it’s a simple solution!

 Yes I know it’s not much of a post.. I want to get something better, but I’m working on a lot of form inputs lately so really… isn’t much challenge.. besides a big headache!  Can’t wait until IE8’s JS debugger.. if it even works that is. lol

Advertisements

1 Comment »

  1. This is my first time pay a visit at here and i am truly impressed to
    read all at one place.

    Comment by how to configure best cable the best modem for xbox live — September 22, 2014 @ 8:16 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: