Showing posts with label base. Show all posts
Showing posts with label base. Show all posts

Thursday, March 29, 2012

Pass parameters to User Control

Hi

I am using a User Control which is referenced by an ASPX page.

How can I pass a string parameter to the user control, from the base ASPX
page.

Thanks

BenHi Ben,

Create a public method in the usercontrol and access the same from the aspx
page.

Ex:

Code in myusercontrol.ascx.cs
public void PublicMethodInUsercontrol(string valuetopasstocontrol)
{
privatevariable = valuetopasstocontrol;
}

Code in the aspx page.

usercontrolinstance.PublicMethodInUsercontrol("MyValueFromPage");

HTH
Regards
Ashish M Bhonkiya

"Ben" <Ben@.nospam.com> wrote in message
news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am using a User Control which is referenced by an ASPX page.
> How can I pass a string parameter to the user control, from the base ASPX
> page.
> Thanks
> Ben
For this purpose I used to create properties (in user control). This way you
can also pass parameters from aspx file (html).
You can access Session to retrieve values. There're plenty of ways. In case
you need some code, I'll try to post.

--
With the best wishes,
Shaul Feldman
"Ben" <Ben@.nospam.com> wrote in message
news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am using a User Control which is referenced by an ASPX page.
> How can I pass a string parameter to the user control, from the base ASPX
> page.
> Thanks
> Ben
Sorry for the delay in replying:

I have heard that you can use this method to pass the parameter:

<%@.Register tagprefix="CodeLib" Tagname="usrMain" src="http://pics.10026.com/?src=usrMain.ascx" %
<CodeLib:usrMain bodyData="usrText.ascx" linksPage="NoLinks"
requireSecure="False" runat="server" ID="usrMain"/
But the problem is that I cannot seem to extract the data on the ASCX page

Thanks Ben

"Shaul Feldman" <sfeldman@.writeme.com> wrote in message
news:e$%23BiHkJEHA.3944@.tk2msftngp13.phx.gbl...
> For this purpose I used to create properties (in user control). This way
you
> can also pass parameters from aspx file (html).
> You can access Session to retrieve values. There're plenty of ways. In
case
> you need some code, I'll try to post.
> --
> With the best wishes,
> Shaul Feldman
> "Ben" <Ben@.nospam.com> wrote in message
> news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
> > Hi
> > I am using a User Control which is referenced by an ASPX page.
> > How can I pass a string parameter to the user control, from the base
ASPX
> > page.
> > Thanks
> > Ben
Help! I have an aspx that loads the ascx with parameters in a
placeholder as textboxes. On my postback I can't get the values out
of the textboxes. They are still on the screen so I'm sure they are
there.

I'm having a hard time. I've been told they should just be there.
aspx
ascx
ascxwp

The ascxwp is the user control that holds the textboxes.

I assume someone has figured this out. We have 3 asp programmers and
we are all stumped.

"Shaul Feldman" <sfeldman@.writeme.com> wrote in message news:<e$#BiHkJEHA.3944@.tk2msftngp13.phx.gbl>...
> For this purpose I used to create properties (in user control). This way you
> can also pass parameters from aspx file (html).
> You can access Session to retrieve values. There're plenty of ways. In case
> you need some code, I'll try to post.
> --
> With the best wishes,
> Shaul Feldman
> "Ben" <Ben@.nospam.com> wrote in message
> news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
> > Hi
> > I am using a User Control which is referenced by an ASPX page.
> > How can I pass a string parameter to the user control, from the base ASPX
> > page.
> > Thanks
> > Ben
Implement Properties inside of your UserControl
e.g.

Public Property FirstName() as String
Get
Return txtFirstName.text
End Get
Set (value as String)
txtFirstName.text=value
end set
end property

Then just access the properties
"Lynne K." <ltgaer@.assurity.com> wrote in message
news:7a65e5b4.0405110605.559f0d2d@.posting.google.c om...
> Help! I have an aspx that loads the ascx with parameters in a
> placeholder as textboxes. On my postback I can't get the values out
> of the textboxes. They are still on the screen so I'm sure they are
> there.
> I'm having a hard time. I've been told they should just be there.
> aspx
> ascx
> ascxwp
> The ascxwp is the user control that holds the textboxes.
> I assume someone has figured this out. We have 3 asp programmers and
> we are all stumped.
> "Shaul Feldman" <sfeldman@.writeme.com> wrote in message
news:<e$#BiHkJEHA.3944@.tk2msftngp13.phx.gbl>...
> > For this purpose I used to create properties (in user control). This way
you
> > can also pass parameters from aspx file (html).
> > You can access Session to retrieve values. There're plenty of ways. In
case
> > you need some code, I'll try to post.
> > --
> > With the best wishes,
> > Shaul Feldman
> > "Ben" <Ben@.nospam.com> wrote in message
> > news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
> > > Hi
> > > > I am using a User Control which is referenced by an ASPX page.
> > > > How can I pass a string parameter to the user control, from the base
ASPX
> > > page.
> > > > Thanks
> > > > Ben
> >

Pass parameters to User Control

Hi
I am using a User Control which is referenced by an ASPX page.
How can I pass a string parameter to the user control, from the base ASPX
page.
Thanks
BenHi Ben,
Create a public method in the usercontrol and access the same from the aspx
page.
Ex:
Code in myusercontrol.ascx.cs
public void PublicMethodInUsercontrol(string valuetopasstocontrol)
{
privatevariable = valuetopasstocontrol;
}
Code in the aspx page.
usercontrolinstance.PublicMethodInUsercontrol("MyValueFromPage");
HTH
Regards
Ashish M Bhonkiya
"Ben" <Ben@.nospam.com> wrote in message
news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am using a User Control which is referenced by an ASPX page.
> How can I pass a string parameter to the user control, from the base ASPX
> page.
> Thanks
> Ben
>
For this purpose I used to create properties (in user control). This way you
can also pass parameters from aspx file (html).
You can access Session to retrieve values. There're plenty of ways. In case
you need some code, I'll try to post.
With the best wishes,
Shaul Feldman
"Ben" <Ben@.nospam.com> wrote in message
news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am using a User Control which is referenced by an ASPX page.
> How can I pass a string parameter to the user control, from the base ASPX
> page.
> Thanks
> Ben
>
Sorry for the delay in replying:
I have heard that you can use this method to pass the parameter:
<%@.Register tagprefix="CodeLib" Tagname="usrMain" src="http://pics.10026.com/?src=usrMain.ascx" %>
<CodeLib:usrMain bodyData="usrText.ascx" linksPage="NoLinks"
requireSecure="False" runat="server" ID="usrMain"/>
But the problem is that I cannot seem to extract the data on the ASCX page
Thanks Ben
"Shaul Feldman" <sfeldman@.writeme.com> wrote in message
news:e$%23BiHkJEHA.3944@.tk2msftngp13.phx.gbl...
> For this purpose I used to create properties (in user control). This way
you
> can also pass parameters from aspx file (html).
> You can access Session to retrieve values. There're plenty of ways. In
case
> you need some code, I'll try to post.
> --
> With the best wishes,
> Shaul Feldman
> "Ben" <Ben@.nospam.com> wrote in message
> news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
ASPX
>
Implement Properties inside of your UserControl
e.g.
Public Property FirstName() as String
Get
Return txtFirstName.text
End Get
Set (value as String)
txtFirstName.text=value
end set
end property
Then just access the properties
"Lynne K." <ltgaer@.assurity.com> wrote in message
news:7a65e5b4.0405110605.559f0d2d@.posting.google.com...
> Help! I have an aspx that loads the ascx with parameters in a
> placeholder as textboxes. On my postback I can't get the values out
> of the textboxes. They are still on the screen so I'm sure they are
> there.
> I'm having a hard time. I've been told they should just be there.
> aspx
> ascx
> ascxwp
> The ascxwp is the user control that holds the textboxes.
> I assume someone has figured this out. We have 3 asp programmers and
> we are all stumped.
> "Shaul Feldman" <sfeldman@.writeme.com> wrote in message
news:<e$#BiHkJEHA.3944@.tk2msftngp13.phx.gbl>...
you
case
ASPX

Pass parameters to User Control

Hi

I am using a User Control which is referenced by an ASPX page.

How can I pass a string parameter to the user control, from the base ASPX
page.

Thanks

BenHi Ben,

Create a public method in the usercontrol and access the same from the aspx
page.

Ex:

Code in myusercontrol.ascx.cs
public void PublicMethodInUsercontrol(string valuetopasstocontrol)
{
privatevariable = valuetopasstocontrol;
}

Code in the aspx page.

usercontrolinstance.PublicMethodInUsercontrol("MyValueFromPage");

HTH
Regards
Ashish M Bhonkiya

"Ben" <Ben@.nospam.com> wrote in message
news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am using a User Control which is referenced by an ASPX page.
> How can I pass a string parameter to the user control, from the base ASPX
> page.
> Thanks
> Ben
For this purpose I used to create properties (in user control). This way you
can also pass parameters from aspx file (html).
You can access Session to retrieve values. There're plenty of ways. In case
you need some code, I'll try to post.

--
With the best wishes,
Shaul Feldman
"Ben" <Ben@.nospam.com> wrote in message
news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
> Hi
> I am using a User Control which is referenced by an ASPX page.
> How can I pass a string parameter to the user control, from the base ASPX
> page.
> Thanks
> Ben

Friday, March 16, 2012

Passing a Variable

Ok here I go again, I am for the most part a novice with ASP.NET. I have an FAQ Knowledge base system that I am currently developing. The basics of it are as follows:

Data is stored on SQL DB, Tables have not been created but the tables will be set up accordingly when I reach that stage. THey will contain the information to display to the user querying the system for answers.

Now to the meat of it, and I may be thinking to hard on the steps to make it work but this is what I have come up with to impliment. Basic page that has a menu driven system I guess similiar to MSDN menu system.

//menu
////category1
////////topic1
////////topic2
////////topic3
////////topic4
////category2
////////topic1
////////topic2
////////topic3
////////topic4

Each menu item will target an iframe to the right of it, again similair to MSDN. here is where my dilema comes into play.

I could just create a static page for each menu item and have it target the iframe, but that would defeat the dynamic function of it, not to mention way to much data to enter when I could just enter it once into the DB for uses beyond the FAQ Knowledge base system.

So I was thinking I have asp.net page that is the source for the iframe i.e. [iframe name="faq" src="http://pics.10026.com/?src=faq.aspx"][/iframe]

This faq.aspx would be such that it would maintain the DB connection string and dataset and so forth for actually displaying the data queryed from the DB and each menu item somehow pass a value that when clicked would load the faq.aspx with the value it is and perform a select statment on the DB based upon the value that it was predifined with.

i.e.

//menu
////category1
////////topic1 = 1_1

sending the value 1_1 to the page_load() event where a select statement would query database with value that is 1_1
where 1_1 = topic_id 1234

I guess here is a my idea of what the code could look like

Sub Page_Load()

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

Dim SelectCommand As String = "select * from DB where topic_id = @dotnet.itags.org.topic_id"

MyConnection = New SqlConnection()
MyConnection.ConnectionString="my connection string"
MyCommand = New SqlDataAdapter(SelectCommand, MyConnection)

MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@dotnet.itags.org.topic_id", SqlDbType.Int, 4))
MyCommand.SelectCommand.Parameters("@dotnet.itags.org.topic_id").Value = passedvariable??

DS = new DataSet()
MyCommand.Fill(ds, "DB")

MyDataGrid.DataSource=ds.Tables("DB").DefaultView
MyDataGrid.DataBind()

End Sub

Or something like that. I hope I am getting my point across, my question is how to get that passed variable over to that select statment. I know how to do the select statement just not getting the variable to it. Any suggestions would be a great help.You'll want to pass a parameter in the URL. For example faq.aspx?id=1234

Then you can read it in your code by access the Request.QueryString collection:

MyCommand.SelectCommand.Parameters("@.topic_id").Value = Request.QueryString("id")