Showing posts with label control. Show all posts
Showing posts with label control. Show all posts

Thursday, March 29, 2012

Pass Parameters to Dynamically Loaded Control?

I have a page that dynamically loads a control:

Dim RelatedProductsControlAs Control =LoadControl("~/controls/RelatedProducts.ascx")
RelatedProductsPanel.Controls.Add(RelatedProductsControl)

That works perfectly but the problem is I need to set a Public Property in the control. I know you can pass partameters to the control like this:

LoadControl("~/controls/RelatedProducts.asx", Parameters As Object)

But I am not sure how the create the parameter as an object so that I can pass it? Any help would be greatly appreciated.

Thanks,
Max

Hi,

You can set the public properties of the control as:

Dim RelatedProductsControlAs Control = LoadControl("~/controls/RelatedProducts.ascx")
Ctype(RelatedProductsControl,Relatedproducts) 'here i am casting the control to its class
RelatedProductsControl.PropertyXXX = "something" 'now i can access the properties as i have casted it to the control class
RelatedProductsPanel.Controls.Add(RelatedProductsControl)

Hope this helps,

Vivek


I tried what you suggested and changed my code to this:

Dim RelatedProductsControlAs Control = LoadControl("~/controls/RelatedProducts.ascx")
CType(RelatedProductsControl, RelatedProducts)'here i am casting the control to its class
RelatedProductsControl.PricingEmail =True
RelatedProductsPanel.Controls.Add(RelatedProductsControl)

But I get an error 'Type RelatedProducts in not defined'

Surely I am missing something here?


Dim cAs WebUserControl =CType(LoadControl("~/controls/WebUsercontrol.ascx"), WebUserControl)

c.MySkin ="hj"

Now, this will work only if I can "access" the class WebUsercontrol.vb in my page's page_load. In your case it is giving an error because the control is incontrolsfolder, so unless you add a namespace in your page, or move the control outside of the Controls folder (in the same directory as the page), it will give this error.

HTH,

Vivek


BTW: you can avoid this "type XX not find" issue by creating a <%Register %> tag in your aspx page as:

<%@.RegisterSrc="controls/WebUserControl.ascx"TagName="WebUserControl"TagPrefix="uc1" %>

Just write this tag so that the Page is able to find the UserControl's class (since it is not in the same folder as the page).

But this is an issue when you do not know the name of the control to be created, and AFAIK there is no solution to it because the VS 2005 Website model uses multiple assemblies so using wihthout a common namespace. An alternative is to use Web Application project model (old one followed in VS 2003). You can get the same from:

http://weblogs.asp.net/scottgu/archive/2006/04/05/442032.aspx

Hope this helps,

Vivek


Thank You! Thank You! Thank You!

Your last suggestion worked perfectly and worked with my existing file structure - thanks again!

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

Monday, March 26, 2012

pass the control value from one web form to another form

Hi Experts,

I want to pass the selectedDate value from my calender
form to another web form or a web user control. Could you
please show me how to do this?

Thanks in advance.Tom,

There are a number of choices to do so.

Depending on your needs, you could use Server.Transfer or Response.Redirect
and the query string.

To use the query string

Response.Redirect("pagetwo.aspx?date=" & selectedDate.ToString)

Then on page two:

Dim Date As Date = CType(Request.Querystring.Item("date"), Date)

If you want to use Server.Transfer (Which would be more suited if a number
of variables need to be passed to the second page.) I suggest reading up on
it a bit more. It's fairly easy to do, but can be confusing for the user
because they are moved to page two but their browser's address bar will
still display the first page's url.

If you want some quick code samples I have some in the code library of my
web site: www.aboutfortunate.com. Just use the search box in the code
library area and input: "Server.Transfer".

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche

"tom" <anonymous@.discussions.microsoft.com> wrote in message
news:00d201c3a947$75660be0$a401280a@.phx.gbl...
> Hi Experts,
> I want to pass the selectedDate value from my calender
> form to another web form or a web user control. Could you
> please show me how to do this?
> Thanks in advance.
Here's a nice, simple way to pass values from one page to another:
(VB.NET code)

'Add data to the context object before transferring
Context.Items("myParameter") = x
Server.Transfer("WebForm2.aspx")

Then, in WebForm2.aspx:

'Grab data from the context property
Dim x as Integer = CType(Context.Items("myParameter"),Integer)

Of course there are a number of ways to pass values from one page to
another, such as using the querystring, cookies, session,
context, saving to a temporary table in the database between each page, etc.
You'll have to decide which technique is best for your application.
Here are several good articles on the subject to help you decide.
http://msdn.microsoft.com/msdnmag/i...te/default.aspx

http://www.aspalliance.com/kenc/passval.aspx

http://www.dotnetjunkies.com/tutori...?tutorialid=600

http://www.dotnetbips.com/displayarticle.aspx?id=79

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"tom" <anonymous@.discussions.microsoft.com> wrote in message
news:00d201c3a947$75660be0$a401280a@.phx.gbl...
> Hi Experts,
> I want to pass the selectedDate value from my calender
> form to another web form or a web user control. Could you
> please show me how to do this?
> Thanks in advance.
Hi Steve and S. Justin,

Thank you very much for your responses. I'm sorry that I
didn't explain my problem more clearly on my previous
mail. My problem is a different situation. On my page one
there is textbox and the page two only contains a calendar
control. I need to open page one first and click a button
on page one will open the page two. After user selected a
date from the calendar the page two will close and the
date should be shown on the page one's textbox. I'm
struggling with how to pass value back to page one when
the page one is already opened and update page one's data?

Please help me!
Thanks in advance.

>--Original Message--
>Here's a nice, simple way to pass values from one page to
another:
>(VB.NET code)
>'Add data to the context object before transferring
>Context.Items("myParameter") = x
>Server.Transfer("WebForm2.aspx")
>Then, in WebForm2.aspx:
>'Grab data from the context property
>Dim x as Integer = CType(Context.Items
("myParameter"),Integer)
>Of course there are a number of ways to pass values from
one page to
>another, such as using the querystring, cookies, session,
>context, saving to a temporary table in the database
between each page, etc.
>You'll have to decide which technique is best for your
application.
>Here are several good articles on the subject to help you
decide.

>http://msdn.microsoft.com/msdnmag/i.../04/ASPNETUserS
tate/default.aspx
>http://www.aspalliance.com/kenc/passval.aspx
>http://www.dotnetjunkies.com/tutori...?tutorialid=600
>http://www.dotnetbips.com/displayarticle.aspx?id=79
>--
>I hope this helps,
>Steve C. Orr, MCSD, MVP
>http://Steve.Orr.net
>Hire top-notch developers at http://www.able-
consulting.com
>
>"tom" <anonymous@.discussions.microsoft.com> wrote in
message
>news:00d201c3a947$75660be0$a401280a@.phx.gbl...
>> Hi Experts,
>>
>> I want to pass the selectedDate value from my calender
>> form to another web form or a web user control. Could
you
>> please show me how to do this?
>>
>> Thanks in advance.
>>
>
>.
Tom,

I think this article is just what you need:

http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=614

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche

"tom" <anonymous@.discussions.microsoft.com> wrote in message
news:0e5401c3a9ee$cd69a7f0$a301280a@.phx.gbl...
> Hi Steve and S. Justin,
> Thank you very much for your responses. I'm sorry that I
> didn't explain my problem more clearly on my previous
> mail. My problem is a different situation. On my page one
> there is textbox and the page two only contains a calendar
> control. I need to open page one first and click a button
> on page one will open the page two. After user selected a
> date from the calendar the page two will close and the
> date should be shown on the page one's textbox. I'm
> struggling with how to pass value back to page one when
> the page one is already opened and update page one's data?
> Please help me!
> Thanks in advance.
> >--Original Message--
> >Here's a nice, simple way to pass values from one page to
> another:
> >(VB.NET code)
> >'Add data to the context object before transferring
> >Context.Items("myParameter") = x
> >Server.Transfer("WebForm2.aspx")
> >Then, in WebForm2.aspx:
> >'Grab data from the context property
> >Dim x as Integer = CType(Context.Items
> ("myParameter"),Integer)
> >Of course there are a number of ways to pass values from
> one page to
> >another, such as using the querystring, cookies, session,
> >context, saving to a temporary table in the database
> between each page, etc.
> >You'll have to decide which technique is best for your
> application.
> >Here are several good articles on the subject to help you
> decide.
> >http://msdn.microsoft.com/msdnmag/i.../04/ASPNETUserS
> tate/default.aspx
> >http://www.aspalliance.com/kenc/passval.aspx
> >http://www.dotnetjunkies.com/tutori...?tutorialid=600
> >http://www.dotnetbips.com/displayarticle.aspx?id=79
> >--
> >I hope this helps,
> >Steve C. Orr, MCSD, MVP
> >http://Steve.Orr.net
> >Hire top-notch developers at http://www.able-
> consulting.com
> >"tom" <anonymous@.discussions.microsoft.com> wrote in
> message
> >news:00d201c3a947$75660be0$a401280a@.phx.gbl...
> >> Hi Experts,
> >>
> >> I want to pass the selectedDate value from my calender
> >> form to another web form or a web user control. Could
> you
> >> please show me how to do this?
> >>
> >> Thanks in advance.
> >>
> >.

pass value of a variable to user control

Hi,

Trying to pass a value to user control within a page.
1. Couldnt find a way to pass it from code behind file.
2. Trying to pass it from aspx page... using EditURL='<%
"mypage.aspx?myvar=" + myvalue %>' assigns value of EditURL=''
I have tried using a local variable... directly trying to read it off
Request object and even tried using session variable...

could be glad if someone could tell me how to get it right... thanks,

regards,

Hermit DaveYou need to use properties and pass them in the page load events for
example....

Doug Stevens, another MVP has this very useful example whih explains the
approach

http://www.dotnetjunkies.com/Articl...866F720AB013.dc
ik

--
Regards

John Timney (Microsoft ASP.NET MVP)
--------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
--------------

"Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
news:uV5MEnQwDHA.556@.TK2MSFTNGP11.phx.gbl...
> Hi,
> Trying to pass a value to user control within a page.
> 1. Couldnt find a way to pass it from code behind file.
> 2. Trying to pass it from aspx page... using EditURL='<%
> "mypage.aspx?myvar=" + myvalue %>' assigns value of EditURL=''
> I have tried using a local variable... directly trying to read it off
> Request object and even tried using session variable...
> could be glad if someone could tell me how to get it right... thanks,
> regards,
> Hermit Dave
Hello John,

Thanks for the pointer. That article hopefully did show me what i wasnt
doing...
For same reason i did look around for the instance of user control in the
data member declaration earlier and couldnt find it...
Anyho... have to map the instance on aspx page to the code behind.. then i
should be able to populate the properties.. (ealier was passing hard coded
values from within aspx and that worked)
Thanks mate,

Regards,

Hermit Dave

"John Timney (Microsoft MVP)" <timneyj@.despammed.com> wrote in message
news:Od4uotQwDHA.3496@.TK2MSFTNGP11.phx.gbl...
> You need to use properties and pass them in the page load events for
> example....
> Doug Stevens, another MVP has this very useful example whih explains the
> approach
>
http://www.dotnetjunkies.com/Articl...866F720AB013.dc
> ik
>
> --
> Regards
> John Timney (Microsoft ASP.NET MVP)
> --------------
> <shameless_author_plug>
> Professional .NET for Java Developers with C#
> ISBN:1-861007-91-4
> Professional Windows Forms
> ISBN: 1861005547
> Professional JSP 2nd Edition
> ISBN: 1861004958
> Professional JSP
> ISBN: 1861003625
> Beginning JSP Web Development
> ISBN: 1861002092
> </shameless_author_plug>
> --------------
> "Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
> news:uV5MEnQwDHA.556@.TK2MSFTNGP11.phx.gbl...
> > Hi,
> > Trying to pass a value to user control within a page.
> > 1. Couldnt find a way to pass it from code behind file.
> > 2. Trying to pass it from aspx page... using EditURL='<%
> > "mypage.aspx?myvar=" + myvalue %>' assigns value of EditURL=''
> > I have tried using a local variable... directly trying to read it off
> > Request object and even tried using session variable...
> > could be glad if someone could tell me how to get it right... thanks,
> > regards,
> > Hermit Dave
"Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
news:uV5MEnQwDHA.556@.TK2MSFTNGP11.phx.gbl...
> Hi,
> Trying to pass a value to user control within a page.
> 1. Couldnt find a way to pass it from code behind file.
> 2. Trying to pass it from aspx page... using EditURL='<%
> "mypage.aspx?myvar=" + myvalue %>' assigns value of EditURL=''
> I have tried using a local variable... directly trying to read it off
> Request object and even tried using session variable...
> could be glad if someone could tell me how to get it right... thanks,
> regards,
> Hermit Dave

I know you have already been pointed to the Properites as fits your
question.

Just as a side note though, you can also use a Cache object for passing
information to an from controls and web user controls. They are very handy.

--
Rocky Moore
www.HintsAndTips.com

pass value to image control

This is my first time to use asp.net. I just want to get an image name passed from url (by using request.querystring), and then display this image, when user click the image, I also display the mouse coordinate. But I just can not get it to work, please help. Thanks. The following is my code:

<script runat="server">
Sub getCoordinates(sender As Object, e As ImageClickEventArgs)
mess.Text="Coordinates: " & e.x & ", " & e.y
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim imagename as String = Request.QueryString("name")
Dim imagePath as String =Server.MapPath("/keller/portrait/" & imagename)
End Sub
</script>
<html>
<body>
<form runat="server">
<p>Click on the image:</p>
<asp:Image
runat="server"
ImageUrl="<%=iamgePath%>"
OnClick="getCoordinates"/>
<p><asp:label id="mess" runat="server"/></p>
</form>
</body>
</html>
Welcome to the ASP.NET Forums, lily1.

The following update to your code will correctly show the image passed in with the QueryString.

<%@. page language="VB" debug="true" %>
<html>
<head>
<title>This is main Page</title>
<script runat="server"
Sub getCoordinates(sender As Object, e As ImageClickEventArgs)
mess.Text="Coordinates: " & e.x & ", " & e.y
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim imagename as String = Request.QueryString("name")
Dim imagePath As String = Server.MapPath("/keller/portrait/" & imagename & ".gif")
MyImage.ImageUrl = imagePath
End Sub

</script>
<html>
<body>
<form runat="server">
<p>Click on the image:</p>
<asp:Image runat="server"
id="MyImage"
OnClick="getCoordinates" />
<p><asp:label id="mess" runat="server" /></p>
</form>
</body>
</html>

The only difference is that I gave the asp:Image control an ID, and used this ID in your Page_Load code to set its ImageUrl property.

For details of how to get your imagemap working, see the following tutorial:
ImageMap.NET

I hope this helps.
Thanks for your help. I tried your script, The picture can be displayed correctly now, but when i click the picture, I got javascript error, it seems that function 'getCoordinates' does not execute at server instead it tries to run at client side. Here is url of the page:http://user1046822.wx15.registeredsite.com/keller/imagecrop_coodinates.aspx?name=test.jpg . Could you please tell me what is the problem? Thanks again.
> Could you please tell me what is the problem?

You've defined the problem yourself ... that getCoordinates tries to run at the client-side, not at the server.

Please go through the article I provided above. That will explain how to send click coordinates back to your server-side code.

pass value to user control from aspx

I have a user control:
- using LoadControl("MyCtrl.ascx")
MyCtrl _mycontrol = (MyCtrl)LoadControl("MyCtrl.ascx")
Page.Controls.Add(_mycontrol);
_mycontrol.Text
it will be loaded when some events fired.
so how can I pass value to this user control from aspx template file.Hi,
Create a property in user control and set the property in template file or
code file.
Prakash.C
"pei_world" wrote:

> I have a user control:
> - using LoadControl("MyCtrl.ascx")
> MyCtrl _mycontrol = (MyCtrl)LoadControl("MyCtrl.ascx")
> Page.Controls.Add(_mycontrol);
> _mycontrol.Text
> it will be loaded when some events fired.
> so how can I pass value to this user control from aspx template file.
>
>

pass value to user control from aspx

I have a user control:

- using LoadControl("MyCtrl.ascx")
MyCtrl _mycontrol = (MyCtrl)LoadControl("MyCtrl.ascx")
Page.Controls.Add(_mycontrol);
_mycontrol.Text

it will be loaded when some events fired.
so how can I pass value to this user control from aspx template file.Hi,

Create a property in user control and set the property in template file or
code file.

Prakash.C

"pei_world" wrote:

> I have a user control:
> - using LoadControl("MyCtrl.ascx")
> MyCtrl _mycontrol = (MyCtrl)LoadControl("MyCtrl.ascx")
> Page.Controls.Add(_mycontrol);
> _mycontrol.Text
> it will be loaded when some events fired.
> so how can I pass value to this user control from aspx template file.
>

Pass value to Web User Control

Say I have a user control like this one...
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.

Pass values from one user control to a user control on a different aspx page

Hello,

I have an aspx page titled Search.aspx. Within this page, I have a user control titled Search.ascx. I want a user to input search terms, then on the click of a button, I want to pass the values to another page (SearchResults.aspx)...which will then display the results in a user control.

Can someone please give me some suggestions on how to do this?

Thanks a lot!Hello, what you can do is:

inside ur usercontrol, create a method that returns a dataset or datareader. that is, since u are searching using the usercontrol, then the result of ur search will be returned by a method of type either dataset or datareader.

and in ur code-behind of the aspx page u can use it as follows:

protected Myusercontrol user;
private DataSet ds = user.GetResults();

and then u might want to put it in a session variable or xml file and then u will be able to access it from the SearchResults.aspx

but why do u want to show results in another page ?

Saturday, March 24, 2012

Pass variable into a user control

Please help, I've been working on this for hours and can't seem to find an answer online.

I have a main page (index.aspx) that uses a usercontrol (DropDownSearch.ascx). Inside the usercontrol are 3 dropdownlists with a code behind file that fills them with data from a query. The query is based on a variable which is sent by the main (index.aspx) file. Inside the code behind for the main page (index.aspx) I try to send the variable over to the codebehind of the user control, but it keeps failing.

Here is the user control info in index.aspx:
<%@dotnet.itags.org.Register TagPrefix="MyControl" Tagname="DropDownSearch" src="http://pics.10026.com/?src=dropdownsearch.ascx"%>
<MyControl:DropDownSearch ID="SearchMenus" Runat="server"></MyControl:DropDownSearch
Here is the code for the index.aspx.cs:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace MainPage
{
/// <summary>
/// Summary description for index.
/// </summary>
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.RadioButton Functional;
protected System.Web.UI.WebControls.RadioButton Pwb;
protected System.Web.UI.WebControls.RadioButton Decorative;
protected System.Web.UI.WebControls.RadioButton Microelectronics;
public string SqlCat1, SqlCat2;
protected SearchMenus DropDownSearch;

private void Page_Load(object sender, System.EventArgs e)
{

}

protected void CategorySelected(object sender, System.EventArgs e)
{

if (Functional.Checked)
{
SearchMenus.SqlCat1 = "1";
SearchMenus.SqlCat2 = "1";
}

if (Decorative.Checked)
{
SearchMenus.SqlCat1 = "2";
SearchMenus.SqlCat2 = "2";
}

if (Pwb.Checked)
{
SearchMenus.SqlCat1 = "3";
SearchMenus.SqlCat2 = "3";
}

if (Microelectronics.Checked)
{
SearchMenus.SqlCat1 = "4";
SearchMenus.SqlCat2 = "4";
}

}
}
}

Here is the user control code behind (dropdownsearch.ascx.cs):
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Enthone
{
/// <summary>
/// Summary description for tier.
/// </summary>
public class dropdownsearch : System.Web.UI.UserControl
{
SqlConnection SearchConnection;
protected DataSet MyDataSet = new DataSet();
public DropDownList TradeNames, Applications, Processes;
public string SqlCat1, SqlCat2;

private void Page_Load(object sender, System.EventArgs e)
{
SearchConnection = new SqlConnection("Server=localhost;uid=sa;password=;database=Enthone");
string MySqlStatement = "sp_DropDownsSql " +SqlCat1+", "+SqlCat2;
SqlDataAdapter MyAdapter = new SqlDataAdapter(MySqlStatement, SearchConnection);
MyAdapter.Fill(MyDataSet);

TradeNames.DataSource = MyDataSet.Tables["Table"];
TradeNames.DataBind();

Applications.DataSource = MyDataSet.Tables["Table1"];
Applications.DataBind();

Processes.DataSource = MyDataSet.Tables["Table2"];
Processes.DataBind();

SearchConnection.Close();
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

}
}

ThanksHow is it failing? Do you get an exception? (If so, what is the complete exception text?) Incorrect results? What's going wrong?

Don
When I go to build it from vs.net I get this error in the index.aspx.cs file, "c:\inetpub\wwwroot\MyApp\index.aspx.cs(25): The type or namespace name 'SearchMenus' could not be found (are you missing a using directive or an assembly reference?)
"
Okay, that means that it can't find the SearchMenus namespace. Where is that located? In another project? Is it open in your VS.NET solution file? You'll need to add a reference to it in Solution Explorer, by right-clicking on References in the project with Index.aspx and adding a reference to the project or DLL.

There are lots of ways to configure these things in VS.NET though, so explain where SearchMenus is located and we should be able to figure out what's wrong.

Don
O.K. I got the whole thing working, but would definitly appreciatea look at my code to make sure I'm handling it the right way...

User Control Info on index.aspx:


<%@.Register TagPrefix="MyControl" Tagname="DropDownSearch" src="http://pics.10026.com/?src=dropdownsearch.ascx"%
<MyControl:DropDownSearch ID="SearchMenus" Runat="server"></MyControl:DropDownSearch>

Code Behind of index.aspx:


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace MyNamespace
{
/// <summary>
/// Summary description for index.
/// </summary>
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.RadioButton Functional;
protected System.Web.UI.WebControls.RadioButton Pwb;
protected System.Web.UI.WebControls.RadioButton Decorative;
protected System.Web.UI.WebControls.RadioButton Microelectronics;
public string SqlCat1, SqlCat2;
protected MyNamespace.dropdownsearch SearchMenus;

private void InitializeComponent()
{

}

private void Page_Load(object sender, System.EventArgs e)
{
}

protected void CategorySelected(object sender, System.EventArgs e)
{

if (Functional.Checked)
{
SearchMenus.SqlCat1 = "1";
SearchMenus.SqlCat2 = "1";
SearchMenus.DbCall();
}

if (Decorative.Checked)
{
SearchMenus.SqlCat1 = "2";
SearchMenus.SqlCat2 = "2";
SearchMenus.DbCall();
}

if (Pwb.Checked)
{
SearchMenus.SqlCat1 = "3";
SearchMenus.SqlCat2 = "3";
SearchMenus.DbCall();
}

if (Microelectronics.Checked)
{
SearchMenus.SqlCat1 = "4";
SearchMenus.SqlCat2 = "4";
SearchMenus.DbCall();
}

}
}
}


Code behind of User Control:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace MyNamespace
{
/// <summary>
/// Summary description for tier.
/// </summary>
public class dropdownsearch : System.Web.UI.UserControl
{
SqlConnection SearchConnection;
protected DataSet MyDataSet = new DataSet();
public DropDownList TradeNames, Applications, Processes;
public Label MyLabel;
private string _SqlCat1;
private string _SqlCat2;

public string SqlCat1
{

get
{
return _SqlCat1;
}
set
{
_SqlCat1 = value;
}
}

public string SqlCat2
{

get
{
return _SqlCat2;
}
set
{
_SqlCat2 = value;
}
}

private void Page_Init(object sender, System.EventArgs e){

}

private void Page_Load(object sender, System.EventArgs e)
{
}

public void DbCall()
{
SearchConnection = new SqlConnection("Server=localhost;uid=sa;password=;database=db");
string MySqlStatement = "sp_DropDownsSql " +SqlCat1+", "+SqlCat2;
SqlDataAdapter MyAdapter = new SqlDataAdapter(MySqlStatement, SearchConnection);
MyAdapter.Fill(MyDataSet);

TradeNames.DataSource = MyDataSet.Tables["Table"];
TradeNames.DataBind();

Applications.DataSource = MyDataSet.Tables["Table1"];
Applications.DataBind();

Processes.DataSource = MyDataSet.Tables["Table2"];
Processes.DataBind();

SearchConnection.Close();
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

}
}

Thanks

Pass Variable Value To User Control From Host Page

I am trying to pass the value of a varible to a user control (code behind) from the host page of the user control. In the uc code behind I am using Get...Set to retrive the value and if I use a static string (i.e "blk") it works but I cannot get it to work using (<%#variable%>. Here is the code:

In the user control code behind

Public mainSkin As String

Public Property ucSkin() As String
Get
Return ucSkin
End Get
Set(ByVal value As String)
mainSkin = value
End Set
End Property

Here is the code from the host page

<jsFlsAd:flsAd id="FlsAd" runat="server" ucSkin= "<%#varSkin%>"></jsFlsAd:flsAd>

Where varSkin is declared as Public in the code behind of the host page.

The above line does not work, however if I change it to:

<jsFlsAd:flsAd id="FlsAd" runat="server" ucSkin= "blk"></jsFlsAd:flsAd>

That will work.
Can someone help me understand what I am doing wrong?Hmm try taking out the " around <%#varskin%>
ie:

<jsFlsAd:flsAd id="FlsAd" runat="server" ucSkin= <%#varSkin%> ></jsFlsAd:flsAd>
Hmm try taking out the " around <%#varskin%>
ie:

<jsFlsAd:flsAd id="FlsAd" runat="server" ucSkin= <%#varSkin%> ></jsFlsAd:flsAd>

I tried that and it didnt work either. The way I got it solved for all who comes across this:

In the Page_Init sub I used

FlsAd.ucSkin = varSkin

Where
FlsAd = The id of the User Control
ucSkin is the custom property
varSkin is the variable that holds the value that I wanted to pass.

All is fine. Thanks for the reply

Pass Variable To User Control

Hi all. I have a user control I'm using as my "include" file for my
flash navigation. My asp.net app is written in vb.net. The swf file
takes a parameter which I would like to pass into my user control.
Ideally i'd like to do something like this:
<object type="application/x-shockwave-flash"
data="flash/navigation.swf?page=<%pageName%>" width="850" height="148">
<param name="movie" value="flash/navigation.swf?page=<%pageName%>" />
<param name="quality" value="high" />
<param name="bgcolor" value="#000000" />
</object>
So how, in all my other pages I'd like to call it like this:
<myControl:incNavigation runat="server" ID="theNavigation"
pageName="home" />if you make PageName a property of the user control, this is pretty easy.
private _pageName as string
public property PageName as String
get
return _pageName
end get
set (value as string)
_pageName = value
end set
end property
public sub void Page_Load(...)
..
end sub
you can then do, as you want
<myControl:incNavigation runat="server" ID="theNavigation" PageName="home"
/>
and use PageName in your object, but make sure to use <%= PageName %> (you
were missing the = in your example)
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
<rhungund@.gmail.com> wrote in message
news:1134604813.689597.220380@.g43g2000cwa.googlegroups.com...
> Hi all. I have a user control I'm using as my "include" file for my
> flash navigation. My asp.net app is written in vb.net. The swf file
> takes a parameter which I would like to pass into my user control.
> Ideally i'd like to do something like this:
> <object type="application/x-shockwave-flash"
> data="flash/navigation.swf?page=<%pageName%>" width="850" height="148">
> <param name="movie" value="flash/navigation.swf?page=<%pageName%>" />
> <param name="quality" value="high" />
> <param name="bgcolor" value="#000000" />
> </object>
> So how, in all my other pages I'd like to call it like this:
> <myControl:incNavigation runat="server" ID="theNavigation"
> pageName="home" />
>
great. that worked! thank you.

Pass variables to header control (.asxc web user control)?

How can I pass variables to a header control?

Generically, I have a series of pages that all use the same header and footer controls. I want each page to have it's own values for a few variables, and the header page needs to recognize those values and change some html based on those values. The html to be changed is just class names on tds, I'm assuming for it to work that maybe I need to change that to something .net can access easier.

Specifically, I tried just making the variables in the pages's .aspx.vb files and writing them out in the header's .aspx file (right where they'd go in the control) but it's errors and tells me I need to declare the variables in the header control.Try this (in C#)

In your code behind for the Header control:


private string _YourVariable = "";

public string YourVariable
{
set
{
_YourVariable = value.ToLower();
}
}

and in the HTML of the page containing the control:


<uc1:YourHeader id="YourHeader1" runat="server" YourVariable="TheValueOfYourVariableHere"></uc1:YourHeader >

Hope this helps,
Nic
Thank you! I will work on it. I'm using vb, so I'll let you know how it goes.

Question: does the header control line allow multiple variables or just one?

Ie,


<uc1:YourHeader id="YourHeader1" runat="server" YourVariable="TheValueOfYourVariableHere" YourVar1="SomeValueY" YourVar2="SomeValueX" YourVar3="SomeValueZ" ></uc1:YourHeader

As many as you want.
Good to hear I can have several variables there, thanks.

Ok, I've had no luck creating equivalent code in vb, yet it looks so straight forward... make a local variable, set it to "", then give the local variable the value of the 1st one... does that sound about right?

:?
Update: Success!
Used this link (http://www.kamalpatel.net/ConvertCSharp2VB.aspx), followed your suggestions, and it works! Now I understand better how to approach this in the future.

Thanks for your help. :)

Pass VB Variable to ASP Control Property

Hi everyone,

this must be easy, but I can't get it right.

How do I pass the VBvariable created at page_load to the property of a
web control:

....
<asp:DropDownList ID="cbo1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="<%=VBVariable%>"
....

What is the correct syntax for DataTextField="<%=VBVariable%>"?

Best regards

Robert"Robert Bevington" <rbevington@.freenet.dewrote in message
news:u8YBYzLxHHA.4612@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

Hi everyone,
>
this must be easy, but I can't get it right.
>
How do I pass the VBvariable created at page_load to the property of a web
control:
>
...
<asp:DropDownList ID="cbo1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="<%=VBVariable%>"
...
>
What is the correct syntax for DataTextField="<%=VBVariable%>"?


Looks OK to me - what error(s) are you getting...?

Also, I'm assuming that VBVariable *does* actually contain a value... :-)

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Hi Mark,

If I hard code the variable everything works fine. If Then replace the
text "ATT_Department" with "<%=VBVariable%>", I got the following message:

DataBinding: System.Data.DataRowView enthlt keine Eigenschaft mit dem
Namen <%=ATT_Name %>.

Translated to English: DataBinding: System.Data.DataRowView has no
property named <%=ATT_Name %>

In Debug mode, if I place the mouse over the variable it reads
"ATT_Department". So it does have a value.

Any ideas?

Rob

Mark Rae [MVP] schrieb:

Quote:

Originally Posted by

"Robert Bevington" <rbevington@.freenet.dewrote in message
news:u8YBYzLxHHA.4612@.TK2MSFTNGP04.phx.gbl...
>

Quote:

Originally Posted by

>Hi everyone,
>>
>this must be easy, but I can't get it right.
>>
>How do I pass the VBvariable created at page_load to the property of a
>web control:
>>
>...
><asp:DropDownList ID="cbo1" runat="server" DataSourceID="SqlDataSource1"
> DataTextField="<%=VBVariable%>"
>...
>>
>What is the correct syntax for DataTextField="<%=VBVariable%>"?


>
Looks OK to me - what error(s) are you getting...?
>
Also, I'm assuming that VBVariable *does* actually contain a value... :-)
>
>

pass vaules between user control (ascx) and aspx page?

Any one have examples or links of how to pass vaules between user control (ascx) and aspx page?

I've been able to pass a value from an aspx page to a user control called in it by adding the variable name = "somevalue" inside the user control tag.

But now I want to have a value from a user control's textbox after a button is clicked, availble to the aspx page.

This seems so simple... and yet I am so lost :)Hi,

In the user Control you can make public properties that will return the string writtin in the TextBox of User Control.

And then in the webform.apsx page you can make an instance of the UserControl and use that property to get the value which is returned from the TextBox.
Thank you!

I did a search on google for those terms and found this article ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconexposingpageletproperties.asp ), and it looks like it goes into detail on public properties of a user control.

Thanks. :)
Am I missing something?
Can the user control properties only be changed from the page that calls the user control, is it possible the other way around, so that in the user control the properties are changed and the page that calls the uc can access those? Two way street or only one way? :)

Pass VB Variable to ASP Control Property

Hi everyone,
this must be easy, but I can't get it right.
How do I pass the VBvariable created at page_load to the property of a
web control:
...
<asp:DropDownList ID="cbo1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="<%=VBVariable%>"
...
What is the correct syntax for DataTextField="<%=VBVariable%>"?
Best regards
Robert"Robert Bevington" <rbevington@.freenet.de> wrote in message
news:u8YBYzLxHHA.4612@.TK2MSFTNGP04.phx.gbl...

> Hi everyone,
> this must be easy, but I can't get it right.
> How do I pass the VBvariable created at page_load to the property of a web
> control:
> ...
> <asp:DropDownList ID="cbo1" runat="server" DataSourceID="SqlDataSource1"
> DataTextField="<%=VBVariable%>"
> ...
> What is the correct syntax for DataTextField="<%=VBVariable%>"?
Looks OK to me - what error(s) are you getting...?
Also, I'm assuming that VBVariable *does* actually contain a value... :-)
Mark Rae
ASP.NET MVP
http://www.markrae.net
Hi Mark,
If I hard code the variable everything works fine. If Then replace the
text "ATT_Department" with "<%=VBVariable%>", I got the following message:
DataBinding: System.Data.DataRowView enthlt keine Eigenschaft mit dem
Namen <%=ATT_Name %>.
Translated to English: DataBinding: System.Data.DataRowView has no
property named <%=ATT_Name %>
In Debug mode, if I place the mouse over the variable it reads
"ATT_Department". So it does have a value.
Any ideas?
Rob
Mark Rae [MVP] schrieb:
> "Robert Bevington" <rbevington@.freenet.de> wrote in message
> news:u8YBYzLxHHA.4612@.TK2MSFTNGP04.phx.gbl...
>
> Looks OK to me - what error(s) are you getting...?
> Also, I'm assuming that VBVariable *does* actually contain a value... :-)
>
"Robert Bevington" <rbevington@.freenet.de> wrote in message
news:%23zKYDJMxHHA.3652@.TK2MSFTNGP04.phx.gbl...

> If I hard code the variable everything works fine. If Then replace the
> text "ATT_Department" with "<%=VBVariable%>", I got the following message:
> DataBinding: System.Data.DataRowView enthlt keine Eigenschaft mit dem
> Namen <%=ATT_Name %>.
> Translated to English: DataBinding: System.Data.DataRowView has no
> property named <%=ATT_Name %>
> In Debug mode, if I place the mouse over the variable it reads
> "ATT_Department". So it does have a value.
> Any ideas?
How are you declaring the server-side variable? In order to visible to the
aspx page, server-side variables need to be Public or Protected.
Mark Rae
ASP.NET MVP
http://www.markrae.net

Passing 2 Parameters from Datalist Control?

I have master/detail pages and pass a parameter from master page (datalist control) to detail page using session method.

Session.Add(

"prm_type", DataList1.SelectedValue);
Response.Redirect("detail.aspx");

The code, I had placed in the datalist "selectedindexchanged" method, above works well. In addition to this, I placed a textbox control in the datalist control to pass a second parameter to detail page. But i don't know how to reach that textbox value and pass the parameter to detail page within datalist selectedindexchanged method like above. I tried something like below, but i couldn't figure out.

Session.Add("prm_quantity", ? this must be my textbox control value);

How can i pass a second parameter like this?

Try with this:

TextBox tbText = (TextBox)DataList1.FindControl("TextBox1");
Session.Add("prm_quantity", tbText.Text);


I got an error message on this line:

Session.Add(

"prm_quantity", tbText.Text);

"NullReferenceException was unhandled by user code"
"Object reference not set to an instance of an object"


Hi,

It may be cache issue. Please look at this KB:

http://www.kbalertz.com/Feedback_831382.aspx

Good luck!

Wednesday, March 21, 2012

Passing a query string

I used Repeater control to bind data and I need something like

<a href="http://links.10026.com/?link=showsection.aspx?section=<%# DataBinder.Eval(Container.DataItem, "SectionId") %>"><%# DataBinder.Eval(Container.DataItem, "Name") %></a>

How can I pass what sectionId is selected on the showsection.aspx page? And oh, is this a good way of having something like a navigator? Or is there any other better way? Thanks.Didn't understand the second part of your question...
I solved it through
public void DisplaySections()
{
SectionCollection sectionCollection = SectionAccess.ListExcludeInactive();
Response.Write("<table width='100%' cellspacing='0'>");
foreach (Section section in sectionCollection)
{
Response.Write(string.Format(@."<tr><td class='navbar'><a href='showsection.aspx?section={0}'>{1}</a></td></tr>", section.SectionId, section.Name));
}
Response.Write("<tr><td class='navbar'> </td></tr></table>");
}

and get the section with
public void DisplayLatestWithSection()
{
int id = int.Parse(Request.QueryString["section"].ToString());
Article article = ArticleAccess.LatestWithSection(id);
if (article != null)
{
Response.Write(string.Format(@."<span class='teaser-head'><a href='showarticle.aspx?article={0}'>{1}</a></span><br>", article.ArticleId, article.HtmlTeaserHead));
Response.Write(article.HtmlTeaserDate + "<br>");
Response.Write(article.HtmlTeaserText);
}
}

at the showsection.aspx. Or is there any better way of getting the query string name and value?