how to transfer a dataset and a string from page to user control

M

Mukesh

Hi all


I have to transfer a dataset and a string from a webform to a user
control on the page without using viewstate or session or cookies .
properties method is not working properly. if anybody thinks that is
fine so plz describe me and send me any article or example for that.

How can i do that

Plz send any article if any body have regarding this
plz Also cc to (e-mail address removed)


Thx in advance

Mukesh
(e-mail address removed)
 
V

Vadivel Kumar

In my understanding you have a custom control or user control that
you've placed in a webform. Now, in the webform you have a dataset or
any data that you want to give it back to the control for processing
it.

The best way to do this is to use properties in the control and assign
the dataset from the webform when ever you want to process it.

This is the straight forward way for this issue.

If you tried the same and got failed in any case, try post some code
with a breif explanation about how your're doing it.

Vadivel Kumar
http://www.vadivelk.net
 
M

Mukesh

Vadivel said:
In my understanding you have a custom control or user control that
you've placed in a webform. Now, in the webform you have a dataset or
any data that you want to give it back to the control for processing
it.

The best way to do this is to use properties in the control and assign
the dataset from the webform when ever you want to process it.
this is my example







This is the straight forward way for this issue.

If you tried the same and got failed in any case, try post some code
with a breif explanation about how your're doing it.

Vadivel Kumar
http://www.vadivelk.net


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace property
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.UserControl Test1;
public DataSet ds = new DataSet();
public string qw;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
string select ="select * from PropertyDisplay2";
Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper cmd = db.GetSqlStringCommandWrapper(select);

db.LoadDataSet(cmd,ds,"Results");
qw="jnbdfgkdfjsgh";
Controls.test mk = new Controls.test();
// mk.Mystr="mukesh agarwal";




// Test1.FindControl("DataGrid1").DataBind();
// property.Controls.test mk = new property.Controls.test();
// mk.i=125;
//
// Label lblbvl= (Label)Test1.FindControl("Label1");
// lblbvl.Text= "rjhgkjfdhgkfdjg";
// mk.MyNumber= 321321;

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void dataView1_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
{

}
}
}

namespace property.Controls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for test.
/// </summary>
public class test : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label Label1;
string i;
public string Mystr
{
get
{
return i;
}
set
{
i = value;
}
}


private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Label1.Text += Mystr;


}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
 
W

Walter Wang [MSFT]

Hi Mukesh,

Thank you for your post and sample code.

Normally you use ViewState to store simple property of the User Control,
for example:

public string Mystr
{
get { return ViewState["Mystr"] as string; }
set { ViewState["Mystr"] = value; }
}

And for the DataSet you need to pass to UserControl's DataGrid from the
WebForm, you can directly expose DataGrid's DataSource property:

public object DataSource
{
get { return DataGrid1.DataSource; }
set { DataGrid1.DataSource = value; }
}

Then you can set the DataSource of the UserControl in WebForm:

WebUserControl1 uc1 = FindControl("WebUserControl11") as
WebUserControl1;
uc1.DataSource = ds1;
uc1.DataBind();

You can do this in WebForm's Page_Load.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mukesh

HI Wang
I m using .net 1.1 and vs2003
pl z help me according to the environment.

Thx

Mukesh
 
W

Walter Wang [MSFT]

Hi Mukesh,

Thank you for your update.

I'm not sure about your question on this. I think the code should work in
ASP.NET 1.1. Have you encountered some error when using the code? Please
feel free to post here if you need more help on this.

Have a nice day!

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mukesh

Hello

Mr. Wang

Thanks for your great support

The code is working in asp .net 1.1 with C# after some changes
Thanks again for ur support

Mukesh Agarwal
New Delhi(India)
 
W

Walter Wang [MSFT]

Hi Mukesh,

Appreciate your update and response. I am glad to hear that the problem has
been fixed. If you have any other questions or concerns, please do not
hesitate to contact us. It is always our pleasure to be of assistance.

Have a nice day!

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top