Thursday, March 29, 2012
pass javascript object reference to a session object
var win1 = window.open( ...)
to a Session object
Session["obj1"] =
in a .aspx pageIt is not possible.
Session objects are stored on the server. Client objects are storied on the
client. You can only send text-data. Keep a window open that will hold your
references if you need to.
-- Alex
"mg" wrote:
> How can I pass a javascript object reference
> var win1 = window.open( ...)
> to a Session object
> Session["obj1"] =
> in a .aspx page
Could you be more specific?
Thanks.
"Alex Papadimoulis" wrote:
> It is not possible.
> Session objects are stored on the server. Client objects are storied on th
e
> client. You can only send text-data. Keep a window open that will hold you
r
> references if you need to.
> -- Alex
> "mg" wrote:
>
You cannot pass a window object to the Session object. If you provide more
information about what you are trying to do, someone might be able to help
you better.
Girish Bharadwaj
http://msmvps.com/gbvb
"mg" <mg@.discussions.microsoft.com> wrote in message
news:BA28CC96-461E-41F5-8AE8-06DE179F1CD4@.microsoft.com...
> Could you be more specific?
> Thanks.
> "Alex Papadimoulis" wrote:
>
the
your
What exactly fo you want to do..
Explain maybe i can HELP!
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
Pass Object from one page to another
Hi, I have one page that has several methods that populate an ArrayList with data. I want to be able to pass this populated ArrayList to another page on the site. Is there any way that this can be done? I know values can be passed using the QueryString, but I need the whole ArrayList object to be passed.
Any help would be greatly appreciated.
Thanks
You can store it in a session variable:http://msdn2.microsoft.com/en-us/library/ms178581.aspx
From the page:
By default, session variables can be any valid .NET type. For example, the following code example stores anArrayListof values in a session variable named "StockPicks." Note that the valuereturned by the "StockPicks" session variable must be cast as theappropriate type upon retrieval from theSessionStateItemCollection.
1) You can keep the arraylist in the session object and can access the session object into another page.
2) You can make serializable class file and make the public object. By using context handler you can access the public object into another page.
Regards,
Suhas
Suhas.Chitade:
2) You can make serializable class file and make the public object. By using context handler you can access the public object into another page.
I've never tried this approach before. Would it mean that the same object is available to all users? Also, how long would the object persist?
Monday, March 26, 2012
Pass the values to the sub..
i want to pass these two value to another sub(passvalue ())..
Sub page_load(source as object, E as eventArgs)
strvalue1="value1"
strvalue2="value2"
passvalue()
end sub
sub passvalue()
xxxxxxxxx
end sub
Sub page_load(source as object, E as eventArgs)
strvalue1="value1"
strvalue2="value2"passvalue(strvalue1, strvalue2)
end sub
sub passvalue(byval arg1 as string, byval arg2 as string, etc...)
xxxxxxxxx
end sub
Pass value to Web User Control
private Sections s = new Sections();
private void Page_Load(object sender, System.EventArgs e)
{
}
public Sections Sections
{
get { return s; }
set { s = value; }
}
public void f()
{
if (s.Query.Load())
while (s.MoveNext())
Response.Write(string.Format("<tr><td width='5'><img src='images/arrow.gif'></td><td><a href='showsections.aspx?s={0}'>{1}</a></td></tr>", s.SectionId, s.Title));
}
And I dragged the user control to index.aspx. Now, on page load of index.aspx, I want to pass some value to the user control's Section property. How do I do this? Or is this possible?
Thanks.If you have the User Control on the Page then you can simply use myUserControl.Sections = someValue; This is same as you would do for any other control on your page.
The thing is, even if i dragged the UserControl on my index.aspx, I can't seem to find SectionsControl (my web user control). At design mode though, I can see SectionsControl1 on index.aspx.
Am I missing something here?
Yes that is pretty much the behaviour you expect for any other control you add to a page. When you add a textbox control first time, the name of textbox will be textBox1 and second control will the name textBox2. In the same manner when you add a usercontrol, it will also follow the same behaviour. So in your code you should write this SectionsControl1.Sections = someValue;
It's a bug in VS 2003. You add a control to your page, but it fails to show up in your codebehind.
Go into the codebehind designer region, and declare your control (of the same name as on the page) with events.
Or, when you add your control to your page by dragging, save your page, THEN go into codebehind. It should show up there.
I missed this post last days. Sorry for the late reply. A bug that is, so decided to declare it myself. Thanks guys.
Saturday, March 24, 2012
Pass Web FileObject to a class
I have a file HTML object, I want to pass this object to a class so I can wr
ite a common method for uploading files.
Idea is to avoid coding file saving in the forms submit button, but call a m
ethod that can process the file that just got submitted.
Is this possible at all? Any idea on how to handle this issue?
TIA"kaushas" <kaushas@.discussions.microsoft.com> wrote in message
news:95A6B7BA-F2D9-4B2B-B60F-4BAA7EF1A4ED@.microsoft.com...
> All
> I have a file HTML object, I want to pass this object to a class so I can
write a common method for uploading files.
> Idea is to avoid coding file saving in the forms submit button, but call a
method that can process the file that just got submitted.
> Is this possible at all? Any idea on how to handle this issue?
Do you mean that you want to pass the "file HTML object" to a method of a
class? Just pass it. What problem are you having when you try to do this?
Can you post some code that reproduces the problem?
--
John Saunders
johnwsaundersiii at hotmail
Sorry
I should have been more specific. I was looking for the object type that I n
eeded to define in the method signature... and then I answered my own quest
ion -> it has to be the HtmlInputFile type that needs to be passed to the me
thod... duh
thanks
"John Saunders" wrote:
> "kaushas" <kaushas@.discussions.microsoft.com> wrote in message
> news:95A6B7BA-F2D9-4B2B-B60F-4BAA7EF1A4ED@.microsoft.com...
> write a common method for uploading files.
> method that can process the file that just got submitted.
> Do you mean that you want to pass the "file HTML object" to a method of a
> class? Just pass it. What problem are you having when you try to do this?
> Can you post some code that reproduces the problem?
> --
> John Saunders
> johnwsaundersiii at hotmail
>
>
Pass Web FileObject to a class
I have a file HTML object, I want to pass this object to a class so I can write a common method for uploading files.
Idea is to avoid coding file saving in the forms submit button, but call a method that can process the file that just got submitted.
Is this possible at all? Any idea on how to handle this issue?
TIA"kaushas" <kaushas@.discussions.microsoft.com> wrote in message
news:95A6B7BA-F2D9-4B2B-B60F-4BAA7EF1A4ED@.microsoft.com...
> All
> I have a file HTML object, I want to pass this object to a class so I can
write a common method for uploading files.
> Idea is to avoid coding file saving in the forms submit button, but call a
method that can process the file that just got submitted.
> Is this possible at all? Any idea on how to handle this issue?
Do you mean that you want to pass the "file HTML object" to a method of a
class? Just pass it. What problem are you having when you try to do this?
Can you post some code that reproduces the problem?
--
John Saunders
johnwsaundersiii at hotmail
Sorry
I should have been more specific. I was looking for the object type that I needed to define in the method signature... and then I answered my own question -> it has to be the HtmlInputFile type that needs to be passed to the method... duh
thanks
"John Saunders" wrote:
> "kaushas" <kaushas@.discussions.microsoft.com> wrote in message
> news:95A6B7BA-F2D9-4B2B-B60F-4BAA7EF1A4ED@.microsoft.com...
> > All
> > I have a file HTML object, I want to pass this object to a class so I can
> write a common method for uploading files.
> > Idea is to avoid coding file saving in the forms submit button, but call a
> method that can process the file that just got submitted.
> > Is this possible at all? Any idea on how to handle this issue?
> Do you mean that you want to pass the "file HTML object" to a method of a
> class? Just pass it. What problem are you having when you try to do this?
> Can you post some code that reproduces the problem?
> --
> John Saunders
> johnwsaundersiii at hotmail
>
Wednesday, March 21, 2012
Passing a object to a reflection class
Hello,
I would like to be able to pass an object from my code behind to another class and return a string with all the object properties and values.
IE Book has Book.Title= "The grinch" Book.Author="Tom Jones"
I need to be able to do something like
GetObjectsProperties(book) book is an instance of the class Book
This would returnTitle= "The grinch" Author="Tom Jones"
I undertand I can use System.Reflection for this, however I could not find a good example.
give this a try:
Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load'one of the page properties we're going to read requires us to validate first... Page.Validate()'just as a sample, we'll pass the current page object to inspect the properties Response.Write(GetProps(Me))End Sub Private Function GetProps(ByVal targetAs Object)As String Dim propInfoArray()As System.Reflection.PropertyInfoDim resultAs New System.Text.StringBuilder'get array of propertyinfo objects for our targets Type propInfoArray = target.GetType.GetProperties'iterate through these propertyinfo objectsFor Each propInfoAs System.Reflection.PropertyInfoIn propInfoArrayDim sAs String Try s = Convert.ToString(propInfo.GetValue(target,Nothing))Catch exAs Exception s ="Error reading property"End Try result.AppendFormat("{0}=""{1}"" ", propInfo.Name, s)Next Return result.ToStringEnd Function Hey, thanks for your help.
When converting this to C# , one line of code did not work for me. Please advise.
using System;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NGB.Mobilization.Util;
using System.Reflection;
public partial class Mobilization_Default2 : NGB.GKO.WebUI.GKOPage
{
protected void Page_Load(object sender, EventArgs e)
{
userLinksControl.UserName = this.CurUser.UserName;
ArrayList excludeColumns = new ArrayList();
excludeColumns.Add("UserId");
Response.Write(GetProps(this.CurUser, excludeColumns));
}
private stringGetProps(Object target, ArrayList excludeColumns)
{
//PropertyInfo propInfoArray = new PropertyInfo();
StringBuilder result = new StringBuilder();
//get array of propertyinfo objects for our targets Type
PropertyInfo[] propInfoArray = target.GetType().GetProperties();
// iterate through these propertyinfo objects
foreach(PropertyInfo propInfo in propInfoArray)
{
// Do Not Add Excluded Columns
if (excludeColumns.Contains(propInfo.Name) == false)
{
string s;
try
{
s = propInfo.GetValue(propInfo, null).ToString();
// s = Convert.ToString(propInfo.GetValue(target, Nothing));
}
catch
{
// na
s = "Error reading property";
}
result.AppendFormat("<b>{0}</b> = {1} ", propInfo.Name, s);
}
}
return result.ToString();
}
This prints:
UserName = Error reading propertyFirstName = Error reading propertyLastName = Error reading propertyEmail = Error reading propertyState = Error reading propertyBranch = Error reading propertyDebug = Error reading property
Thanks for your helpmbanavige!
}
change it to this:
s = propInfo.GetValue(target, null).ToString();
awesome it worked. thanks man!
I'm going to make this a "helper" function for my project.
i'll post the code when it's complete
Friday, March 16, 2012
Passing an array as a session variable
I have 2 asp.net forms. In the first form I create a one dimensional array and copy that array into a session object. In the second form I want to read the elements of that array. Everything I've tried results in either a casting error, a late binding error or nothing at all. The following code shows what Iwant to do.
Form one: Dim aArray(2) as stringaArray(0) = "zero"aArray(1) = "one"Session("PassArray") = aArrayForm two: Dim aTest(2) as stringaTest(0) = CType(Session("PassArray(0)"), String)aTest(1) = CType(Session("PassArray(1)"), String)When I run form two in the editor, I can Watch Session("PassArray") and see:Session("PassArray") {System.Array} object-- (0) "zero" string-- (1) "one" stringSo I know it's there and available, but how do I read the extents.Could really use a simple code example to explain what I'm doing wrong.
Hi,
Use this on the second form:
Dim aTest() As String = CType(Session("PassArray"), String())
That did it. Thank you.