Setting Variable In User Control File?

Mar 3, 2010

I am trying to modify a .ascx file, to declare a variable. I've read that this is normally done in the code behind view, but I do not have access to the code behind, and this is a very small addition. We are using DotNetNuke, and in the .ascx file I have written

<script runat="server">
String foo = "bar";
</script>

And this causes the page to explode. I have some experience with PHP, but am very new to .NET. Is there a way to define a variable in a .ascx file in this way? Maybe I have not imported all the correct libraries at the top of the page?

View 7 Replies


Similar Messages:

Web Forms :: Web Parts / Want To Store User Setting In XML File ?

Oct 27, 2010

iam creating a customized dashboard using web parts and i am new in web parts..i wanna a way to store user setting in XML file .. how can i achieve that ?

View 4 Replies

Variable Be Shared Across Multiple User Or A Separate Variable Will Be Created For Each User?

Mar 7, 2011

I am having one doubt regarding the use of static variable in Asp.net pages.I am having one page say UserDetails.aspx.In this page, I have one static variable to store some data specific to a user. So, will this ?

public partial class UserDetails
{
static int numberOfReviews=0;

[code]...

View 5 Replies

Setting A Property For A User Custom Control?

Jan 25, 2010

I have created a user custom control, and what I would like to do is to pass it the text value from a label where I can carry out some other processing.

View 2 Replies

MVC :: Setting Datetime Textbox In User Control?

Mar 29, 2011

I have a user control (ASCX) in Views/Shared/EditorTemplates folder that displays a calendar along side of each datatime field in a form.

Now I need to add two image buttons so that the onclick event will set the value in datatime field next to it. First button

will set the datetime to Now, the second will set the datatime to 12:00:00AM of the current date. I am struggling with the

ID property of the datatime fields that prevents me from setting there value property.

[Code]....

View 1 Replies

Web Forms :: Setting Dropdown In User Control?

Apr 10, 2010

I've got a user control with a dropdown of states. I have a State property that sets the selected value. When I add this control to a page and set the state property, it doesn't set the selected value. If I add some code in the page load event of the user control it does set the selected value.

View 10 Replies

C# - Can't Pass A Variable To A User Control?

Jun 17, 2010

I am using the below example code and have a problem where I can't pass the Request.RawUrl value into an object that extends the Control object (class Test below).When I use the line:

<Test1:Test runat="server" ID="testControl" Target="<%# Request.RawUrl %>"></Test1:Test>

I find that the Target property is never called.If I use this line instead:

<Test1:Test runat="server" ID="testControl" Target="<%# Request.RawUrl %> test"></Test1:Test>

the string value "<%# Request.RawUrl %> test" is passed to the Target property.f I use this line as explained in many posts online:

<Test1:Test runat="server" ID="testControl" Target="<%= Request.RawUrl %>"></Test1:Test>

the string value "<%= Request.RawUrl %>" is passed to the Target property.I need to get the value of Request.RawUrl passed to the Target Property of my Test control object. Does anyone have any ideas where I am going wrong?Control:

namespace Testing
{
public class Test : Control

[code]...

View 1 Replies

C# - Setting Property Default Values For A Web User Control?

Apr 15, 2010

I am trying to build a web user control and set some default values for its properties in the code-behind like this:

[DefaultValue(typeof(int), "50")]
public int Height { get; set; }
[DefaultValue(typeof(string), "string.Empty")]
public string FamilyName { get; set; }
[DefaultValue(typeof(Color), "Orange")]
public System.Drawing.Color ForeColor { get; set; }

When I add the user control to the page and call it without any properties:

<uc1:Usercontrol ID="uc" runat="server" />

the default values are not set and every property is 0 or null.

View 2 Replies

Web Forms :: Dynamic User Control And Setting Properties?

Jan 25, 2011

I have a user control (i.e. ascx) that comprises of two related list boxes (i.e. once you change the selected item in one list the contents of the other list update). I'm adding this user control dynamically to a page on the click event of a button (i.e. using LoadControl).I wish to set the list box datasource properties, as well as the default selected item of the parent list from my parent page so I created public properties in my user control to accomodate this. I also created an event in my user control that notifes the parent page when the selected item changes in one of the list boxes so I can update the contents of the other list box.

I understand that I have to recreate the user control on every postback in order for it to function correctly but I'm not sure exactly how I should be doing it. I've shown below what I have currently - whilst it works the problem is that on postback I'm always creating the user control with all its default properties and then updating the properties that need to change(?). For example, when the choice in theparent list box changes the datasource of the list box is set twice (once in AddControl and then again in OnParentChanged)? As the contents of the list boxes originate in a database it means I'm making unnecessary calls to the database (unless I do some something like store each unique set of data in the ViewState).

I'd be very grateful if someone could review how I've done things and illustrate how perhaps I should be doing things. I'm not sure if the way I've done this is considered the 'correct' way. For example there may be a better way of doing things would avoid setting the properties twice? I'm a bit unsure of the way I've set the datasource properties of the list boxes and bound them. I wished to set the datasource from the parent page because I might have a second user control on my page that may also use the same datasource and I could reuse it (as opposed to each control making its own call to the database) so I'd like to keep this feature if possible.It would be great if posting code in reply that you use my example as a guide so I know what you're referring to.Here's the code for my user control:

[Code]....

[Code]....

Here's the code for my containing page:

[Code]....

View 1 Replies

Creating A User Control With Variable Layout?

Oct 13, 2010

I have a user control which contains a number of child controls. I want to be able to change the layout of the control (i.e. change the markup surrounding the child controls) via a property of the user control, but I don't want to have to duplicate the child controls themselves. This precludes using, say, a MultiView with different versions of the layout in each view, since in that case I'd have to duplicate the controls. I'd also rather use markup than emit the code for the control directly (as you'd do in a server control).

To give a contrived example, say I have a label and a textbox. In one layout, I want the label and textbox to be contained by divs and laid out on top of each other. In an alternate layout, I want them to be contained side by side in a table.

Should I just go ahead and duplicate the controls between each view? It seems like a violation of the DRY principle, but I'm not sure if I have much choice. A partial solution would be making the views of a multiview into naming containers so that I could at least save myself the time of having to prefix the duplicate control IDs with something to make them unique.

View 3 Replies

Access Page Variable From User Control?

Oct 29, 2010

I have a property on a page called

public string productName { get; set; }

I want to access this in my usercontrol code behind. What's the right way to do it?Currently I am doing

((MyPage)Page).productName

But the user control is not compiling. My pagename is MyPage and I have also added a Reference

<%@ Reference VirtualPath="~/MyPage.aspx" %>

View 1 Replies

Web Forms :: Can't Assign Values To Variable In User Control

Jun 17, 2010

I have a simple user control which toggles between the visibility of a few images depending on the UserId. When the page is loaded for the first time, the userID is being assigned correctly (I'm debugging). However, there are two other buttons on the page for filtering the type of users, they are perform their functionality via Ajax (not the toolkit, but the normal javascript ajax) When one of these buttons are clicked, the user control cant get the userid, it always comes up as Zero. Oh, btw, the usercontrol is in a DataRepeater, so it occurs for each of the user.. all the time.. or thats the Idea. I have several other pages like this, (none of them have ajax) and the user control has no problems whatsoever.

My User control code:

[Code]....

And the Data Repeater is something like this:

[Code]....

Here, Immediately after the userControl <ucAB:....> line, I am printing the userid just to see if its valid (by <%# Eval("UserId") %> and the user id's are valid too. I dont understand why the User Control cant pick it up on ajax postback?

View 3 Replies

Web Forms :: Access Page Variable From User Control

Oct 29, 2010

I have a property on a page called

public string productName { get; set;}

I want to access this in my usercontrol code behind. What's the right way to do it? Currently I am doing

(MyPage)Page).productName

But the user control is not compiling. My pagename is MyPage.

View 2 Replies

Web Forms :: Variable Width Image In User Control?

May 17, 2010

I am new to web design so bear with me. I have an .aspx page with a user control at the top that is basically a container for an image. It serves as a banner spanning the entire page. The lower part of the page is a left and right sidebar with a main middle section.

The image is simply some text at the left layered over a background that fades from blue to white, top to bottom. Image size is 90 p. high by 1000 p. wide. How can I get this image to vary width withing the control along with the rest of the page when rendered under different screen resolutions?

View 1 Replies

AJAX :: Odd Behavior On Setting Focus In User Control With Update Panel?

Nov 9, 2010

I'm having a bit of an issue in my ASP.Net application moving focus from a textbox in one user control to a text box in the next user control on the page after postback. I've searched high and low over the last several days to find a solution but, for whatever reason, have been unable to do so.

I have a page that has user controls loaded dynamically to allow a user to enter data.The number and type of user controls loaded to the page is determined at run time based on a database query.It is possible than many controls of the same type can be loaded. Each user control has its own update panel. Within the update panel of each control is a regular asp panel. Inside of the regular panel there are at least 2 server controls (any other controls that may exist in the user control are not affected by this issue) - a text box and a button.The defaultbutton property of the regular panel is set to the ID of the button within the user control. The desired behavior is to allow the user to enter data into the textbox on one user control hit enter to save the data on that user control the application will set focus to the textbox of the next user control on the page after the data from the "current" user control has been saved. Other considerations;

The application uses master pages. We make extensive use of ajax and the ajaxtoolkit in the application. I am using Visual Studio 2010 and .Net 4 The issue - when first entering the page, one can enter data into the first textbox and press the enter key. Data from "current" user control is correctly saved and focus is correctly moved to the next user control on the page.

Data can be entered into the textbox of "new" user control and when the enter key is pressed, the data is correctly save. The focus appears to move correctly to the next user control on the page.Data cannot be entered into the textbox of the control. Pressing the enter key will not save the data (because none was entered) but the focus will move to the textbox of the next user control on the page.

Data can be entered into the textbox of the user control. When the enter key is pressed, the data is correctly saved and the focus appears to move correctly to the textbox of the next control on the pageBasically, steps 3 and 4 are repeated until the end of the user controls on the page, alternating between being able to enter data and not. Other items of note When one is able to enter data into the textbox of a user control, one can correctly tab through the textboxes of each user control until the end of the page When one is not able to enter data into the textbox of a user control, pressing the tab key will take the focus to the address bar of the browser.

I created a much simplified example of the scenario described above and was able to consistently reproduce the "bad" focus behavior. All of the ajax toolkit controls and code where stripped out of the sample to rule the toolkit out as a cause. The behavior still occurs without the toolkit.

I am including the code for default.aspx and WebUserControl1.ascx.

[Code]....

[Code]....

[Code]....

[Code]....

View 2 Replies

C# - Viewstate Variable Lost On User Control Loaded Dynamically

Feb 12, 2010

I have a problem with ViewState. I have an aspx page that has a treeview on the left and an UpdatePanel with an ASP.NET Panel inside on the right. It is in that inner Panel where I load and unload dynamically user controls. I use that update panel to load dynamically controls.

I also made a custom control for my user controls because I need to pass some values from page. On that constructor I use ViewState to store these values.

The first time I load the user control I call its constructor with parameters. When I reload that user control on each postback I use its normal constructor.

My problem is I the values I've stored on ViewState has become null on successive postback.

Update:

This is a piece of my user control:

public class MyUserControl : System.Web.UI.UserControl
{
private int PKId
{
get { return ViewState["pkId"] as int; }
set { ViewState["pkId"] = value; }
}
public MyUserControl(int pkId)
{
this.PKId = pkId;
}
...
}

I'm following this article to load controls dynamically: http://msdn.microsoft.com/en-us/magazine/cc748662.aspx#id0070065.

Second Update:
I also set the same control ID when I load the user control at first time and on each reaload.

Maybe I can use another method to store these values like input hidden fields or Cache. I've choosen ViewState because I don't want to overload server with Session values for each user.

Third update:

I load the controls with this code:

System.Web.UI.UserControl baseControl = LoadControl(ucUrl) as System.Web.UI.UserControl;
if (baseControl != null)
{
baseControl.ID = "DestinationUserControl";
PanelDestination.Controls.Add(baseControl);
}

And reaload with this code:

DynamicControls.CreateDestination ud = this.LoadControl(TrackedUserControl) as DynamicControls.CreateDestination;
if (ud != null)
{
ud.ID = "DestinationUserControl";
PanelDestination.Controls.Add(ud);
}

View 4 Replies

Custom Server Controls :: Custom Control's Constructor / User To Set That variable In The Properties Window After They Drag The Control Onto A Form?

Mar 4, 2010

I have a custom control which inherit from the Table class and in the constructor, it takes a an integer as an argument. There is no empty constructor.

Is there a way for the user to set that variable in the properties window after they drag the control onto a form.

I know some .NET controls, you can set the source for the parameter to different things like another control's property, QueryString using just the properties window.

Right now, I have to create the control dynamically. I read the query string and then created the object.

View 1 Replies

Forms Data Controls :: Setting Properties On Web User Control In Dynamic GridView

Jan 7, 2010

I am in need of some assistance in regards to how to best set the values of properties for a Web User Control which is being included into a cell of a GridView with dynamically created columns. I have tried a few different approaches, but can't seem to get a satisfactory result. Also, to be completely honest, I am not really sure if I am using best practices for what I am trying to accomplish.

First off a little background:I have a GridView for which we will never know the exact number of columns at run time. The columns are predicated by user selection. I am creating the command text for the DataSet on the fly and then looping through the columns of the resulting DataTable in order to use custom TemplateFields. This works ok for just printing out the row values but not so much for when I need to insert the Web User Control into a cell.The Web User Control is in essence a collection of image links which are used as a "Quick Nav" tool. I need to pass the values of 2 fields from each DataRow to the control via properties (for example, CustID and ProductID). I am using custom TemplateField classes inheriting from ITemplate for displaying my fields and extending the DataBinding event like so: [Code]....

This won't work for my User Control as DataBinding is called after the control is loaded into the page and I need the properties to be set before the Page_Load event of the control is fired.Is there a GridView event I should be looking into instead such as RowCreated or RowDataBound? Or should I modify how I loop through the DataTable by doing rows first, then the resulting columns as I've seen done elsewhere?

View 5 Replies

Visual Studio :: Access Master Page Variable From A User Control

Apr 10, 2010

I am using vb.net/asp.net 2005. I have a master page that displays a child content page. The child content page contains a user control that I created. In the user control I would like to access a variable that is set in the Master page.

View 3 Replies

Localization :: Cannot Fix Or Limit User To Setting PC Regional Setting To UK

Dec 23, 2010

I have develop a web application. I have put my web application in my server and user can access from any location.

My server regional and setting is English (US). Now my problem is

1) When user access to my system and his pc setting is English (UK), it will prompt and error

and after i debug i suspect it is because of Datetime conflict (dd/MM/yyyy and MM/dd/yyyy)

2) I cannot fix or limit my user to setting his/her pc regional setting to UK

So what can i do in my web application solve this issue?

(Can i write any code in my client side (.aspx) to convert or do standardization to US)

View 2 Replies

SQL Server :: Setting Value From Query To Session Variable

Mar 11, 2011

I would like to run a SQL query on the codebehind VB page that will also set a value from that query to a Session variable. Also, this needs to be done on the Page_Load.
Example:
[Code]....

View 3 Replies

Web Forms :: Setting A Variable In A Page_load Method?

Jun 14, 2010

In the following code, you'll see that the method 'getImage' is called and passes in a filepath. I want this filepath to be dependant upon a selection on a previous page- so instead of it constantly being 'properties/cedar', it could be 'properties/eastlodge' for example.

[Code]....

View 3 Replies

DataSource Controls :: Setting Parameter Value From A Variable?

Sep 3, 2010

I create a variable in code behind to save today's date.

[Code]....

And I want to save it as a parameter for an accessDataSource but I'm not finding anywhere that tells me how to do this properly. My attempts thus far have been

[Code]....

View 4 Replies

Setting Session Variable On Repeater Item Click?

Mar 1, 2010

first off I can't post the code, so I will do my best to try to explain what I am trying to do. I have a repeater with three literals (a member ID, a name, a uservalue) and three hyperlinks. Each of the hyperlinks goes to a different page (obviously).What I am trying to do is when the user clicks on one of the hyperlinks, (doesn't matter which one because the three literals need to be put into session variables regardless) I want the session variables set to the literal values before calling the next page.How do I get the session variables set when the user clicks on one of the hyperlinks?

View 9 Replies

State Management :: Setting Session Variable From Formview

Apr 13, 2010

I'm building a site (it's amazing how much you can do and still not know what you're doing).I have my visitor login from a login.aspx page and, when authenticated are redirected to a Portal page. On that Portal page at pageload I set a Session variable "UserName" using the User.Identity.Name like this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If User.Identity.Name <> "" And User.Identity.IsAuthenticated = True Then
If Page.IsPostBack = False Then
Session("UserName") = User.Identity.Name
End If
[code]...

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved