C# - How To Use Global Variables In ObjectDataSource.SelectMethod
Sep 10, 2010
I'm using ListView + DataPager + ObjectDataSource mix.
In the implementation of my SelectMethod of an ObjectDataSource I'd like to access a global variable set in the PageLoad() event (the method will return just the proper number of items per page). Although the variable is initialized in PageLoad() it appears to be null in SelectMethod. How can I change that?
[Code]....
View 4 Replies
Similar Messages:
Nov 8, 2010
Is it possible to access an object that is used by ObjectDataSource to retrieve records? For example,
<asp:ObjectDataSource ID="MyDS" runat="server"
SelectMethod="getUsers"
TypeName="DataSources.UserDS"
SelectCountMethod = "getUserNum"/>... </asp:ObjectDataSource>
UserDS class has getUsers that returns DataTable and getUserNum that returns int, this part works as it's supposed. But I wonder if can access the instance of UserDS somehow (not underlying DataTable)?
View 1 Replies
Apr 13, 2010
Can we specify two different methods as SelectMethod of ObjectDataSource at two different events?
I need my Objectdatasource to get filled with one method while at button click event I want to fill it with other overloaded method.
Both the methods have same name and return same data type but they have different input parameters.
View 6 Replies
Mar 31, 2011
how to pass an object to the selectmethod of the objectdatasource control?
View 2 Replies
Mar 27, 2011
how to pass parameters to the selectmethod property of the objectdatasource control.
View 1 Replies
Oct 7, 2010
so here is the setup. I am building a page that has a listview, a datapager, and 3 datapagerfield (2 x NextPreviousPagerField, 1 x NumericPagerField), and a objectdatasource to tide all of this together.
It was all working fine until I put a breakpoint into the SelectMethod specified in the objectdatsource control. It seems like that for each datapagerfield control, it is calling the selectmethod and selectcount method. Hence, whenever a user paged, it calls the database 6 times instead of 2 (I don't have caching turned on atm). If I remove one datapagerfield, it will remove 2 calls.
Now this is build in asp.net 3.5 SP1 in VS2008. When I copied the same code files to a asp.net 4.0 VS2010 solution, it duplicate call seems to be gone.
Is this a bug in asp.net 3.5 SP1?
View 1 Replies
Feb 25, 2011
How do you declare global variables in ASP.NET MVC?
View 6 Replies
Sep 15, 2013
as we do in desktop app, can we use global variables in a web app. it must be client side.
i hv created a class to handle global variables, but the issue is with it. if other user login on another pc at d same time, the variable got re-initialized. i want they must be client/ user specific.
View 6 Replies
Jan 8, 2010
with a problem im having or at least give me an idea about which direction i should be going in.I have an asax file - with the following void Session_Start(object sender, EventArgs e)in that I am storing a session which holds a boolean.This boolean holds a flag which when set to true tells the application to go to the database and retrieve data, if its set to false, it checks the information in memory.I am using master pages and inside my master page i have and ascx files - which holds my navigation items(I build the navigation menu based on certain criteria)on a content page (a page that uses the master page) I perform a function when a button is clicked and I set the session flag to truethe problem is that the flag is not being checked until i refresh the page twice and therefore the menu is not updating until the user clicks to another page.my suspicion is that it is because of the page life cycle (the event handlers are done AFTER page load) - is there anyway around this?Is there any web page links you have got that I cant google? (yes i have googled but to little luck - maybe im using the wrong search term).on an additional note im trying to avoid like the plague - storing anything in the viewstate
View 9 Replies
Jan 9, 2014
it's possible to declear global variable in asp.net C#.
View 1 Replies
Feb 13, 2011
i declared a static variable in global.asax file like below
<%@ Application Language="C#" %>
<script runat="server">
static string Sv;
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
i want to access this variable in aspx page. how can i access this variable.
View 2 Replies
Dec 18, 2010
I am working with Google maps api V3. I need to get the values of the getSouthWest & getNorthEast bounds of my map. To do this the 'bounds_changed' event needs to be fired in order to get the new values. This is all good, however, I need to access these values from outside the event and passed to a server side function (more specifically, I don't want to call my server side function every time the map bounds are changed).
My code is:
//Global
var sw, nw, Searchbounds;
function myFunc(){
google.maps.event.addListener(map, 'bounds_changed', function() {
Searchbounds = map.getBounds();
sw = Searchbounds.getSouthWest();
ne = Searchbounds.getNorthEast();
});
CallServerSideWebService(sw.lat(), ne.lng(), ne.lat(), ne.lng());
}
When executing this code I get the error message sw is undefined.
View 2 Replies
Sep 3, 2010
I have a custom class that pulls user information from a SQL Server table. Now that I'm expanding the site from a single page to others. I want to shift the code to the Session_Start event so that the information is always loaded when the site is accessed. How do I call my custom code from global.asax since its script and not a class.
View 5 Replies
Feb 7, 2011
For some reason it seems as though variables that I declare in javascript sometimes persist themselves across applications even when I do a response.redirect. I thought that a response.redirect would clear them out.
View 1 Replies
Feb 8, 2011
I know there is a couple answered questions on here regarding "request scoped" globals, but I want to nit-pick on something specifically and maybe squeeze some extra enlightenment out of one or two of you.I have an ASP.NET C# Website and a static Dictionary of objects (loaded from DB once on Application start). Each page request will need to do a lookup in the Dictionary (based on a key derived from the request url/etc) and get the appropriate object.The issue is I'm trying to maximize efficiency by reducing the lookups to the Dictionary per Request. Doing just a single lookup within a Page itself is easy enough and I can pass the object to sub controls, etc too.. but global.asax is separate from the Page and it also needs to use the object (in Application_BeginRequest and Session_Start).
So is doing a Dictionary lookup once in Application_BeginRequest, once (when necessary) in Session_Start and once in the Page negligible speed wise, even if there are many requests coming in every second?I would like it if I could just have a Request scoped global variable that I can easily call upon.. the only one I see available though is HttpContext.Current.Items and that is a Dictionary itself.Am I beingridiculously nit-picky with my concern over efficiency? or will these milliseconds (nanoseconds?) get me in the long run when more and more requests are being made?
PS. I currently only have around 100 objects in the Dictionary although this may increase in the future.
View 2 Replies
Aug 8, 2010
i am trying to collect 2 variables from one hyperlink, and use those variables in the page_load to set as session. but i don't know how to collect those 2 variables
such :
<a href="javascript:;" onclick="wsChangeColor('mainData', '#FF0000','#FFE4E1');return false;" title="Change color" id="red">1</a>
i would like to collect '#FF0000','#FFE4E1' or direct set '#FF0000','#FFE4E1' to string then send to pageload, how can i do this by only clicking on it ?
View 1 Replies
Jan 2, 2010
I have this code in javascript: var x = e.mapX; It gets the X-coordinate of a map. What I want to do is that I want to store this into a c# variable. I have a class named Test with an integer property X. I want to store var x into X. In the codebehind, I have this on the Page_Load: Test test = new Test(); Then I am trying this on the javascript code: var x = e.mapX;
View 16 Replies
Mar 5, 2011
whats the exact use of static variables in overall programming in .net and for asp.net...
Recently i went for the interview where interviewer asked me 2 question which i was not sure for the same..
whats the use of session object, i said sessions are the server side object, they are used when you want to store user specific data at server side, then he asked what if i want to use static variables for the same, i was mum, can anyone tell me how asp.net will behave if i store the user specific information in static variables.If i use cookies which are the best option to store the data at client side (not sensitive one), but what if user has disabled cookies on his machine, will my application would crash.
View 3 Replies
Oct 11, 2010
I have a grid view that bounded to an object data source that select data from type of student
public class student
{
int id;
[code]...
View 2 Replies
Apr 6, 2011
I tried binding a ListBox to an Object Data Source, but I can’t get the field to show up in the Data Source Configuration Wizzard for the ListBox. I got it working programatically populating the listbox using the DataReader but I’d like to be able to use the Object Data Source (Unless there are compelling reasons not to that I haven’t heard of yet.)
The code:
[code]....
View 12 Replies
Jul 28, 2010
i created an objectdatasource and bind DetailView to it.i want to set the objectdatasource.datasource to a object (for example Member class that is an Entity) it means that i want to show just one record to this with my custom method that is MemberModel.GetMemberByNationalID(string nationalID)
View 1 Replies
Aug 3, 2010
I have a gridview I want to populate with an ObjectDataSource.Problem is, when I use the wizard, I cannot find the page the ObjectDataSource belongs to, in the business object list. I can see the classes in the App_Data and App_Code, but I want to use a method in this current page´s codebehind class.
View 5 Replies
Feb 2, 2011
System.NotSupportedException was unhandled by user code
Message=The data source does not support sorting.
Source=namespace
StackTrace:
at namespace.Admin.ToolkitScriptManager1_AsyncPostBackError(Object sender, AsyncPostBackErrorEventArgs e) in C:projectMaster.cs:line 27
at System.Web.UI.ScriptManager.OnAsyncPostBackError(AsyncPostBackErrorEventArgs e)
at System.Web.UI.PageRequestManager.OnPageError(Object sender, EventArgs e)
at System.Web.UI.TemplateControl.OnError(EventArgs e)
at System.Web.UI.Page.HandleError(Exception e).......
below is my code using for simple gridview and i am only having problem with the sorting and paging is working as expected and i even define the ONSorting event but it still throws me an error: The data source does not support sorting.
namespace mynamespace
{
public class Product
{
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
private string _code;
public string Code
{
get { return _code; }
set { _code = value; }
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
<asp:GridView ID="GridView1" runat="server" DataKeyNames="Id"
AutoGenerateColumns="False" OnSorting="gridview1_Sorting" DataSourceID="ObjectDataSource1" >
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id"
SortExpression="Id" ReadOnly="True" />
<asp:BoundField DataField="Code" HeaderText="Code"
SortExpression="Code" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:TemplateField HeaderText="State/Province" SortExpression="StateProvinceName".......
View 1 Replies
Sep 30, 2010
This has been covered a couple of times, without a suitable answer:[URL]
I have created a custom paging data class that is used with an ObjectDataSource. In intial tests, I found it was performing worse than my old SqlDataSource code. Whilst investigating, I found that for every page load, the ObjectDataSource is being created and binding twice.
Investigating the links above led me to believe this could be a bug (or unexplained behavior) in regards to changing my GridView's column visibility in the OnDataBound event like so:
protected void gvContacts_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.Pager && e.Row.Cells[0].Text != gvContacts.EmptyDataText)
{
e.Row.Cells[0].Visible = false;
if (Convert.ToInt16(lstSearchType.SelectedValue) == ADDRESS)
{
gvContacts.Columns[2].ItemStyle.Width = Unit.Percentage(30);
gvContacts.Columns[3].Visible = true;
gvContacts.Columns[3].ItemStyle.Width = Unit.Percentage(20);
}
else
{
gvContacts.Columns[2].ItemStyle.Width = Unit.Percentage(50);
gvContacts.Columns[3].Visible = false;
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["ID"] = "contact_" + e.Row.Cells[0].Text;
e.Row.Attributes["onclick"] = "javascript:selectRow($(this).attr('id').replace('contact_',''),2);";
e.Row.Attributes["ondblclick"] = "javascript:openContact($(this).attr('id').replace('contact_',''),''); selectRow($(this).attr('id').replace('contact_',''),2);";
//E-mail link
if (e.Row.Cells[4].Text != " ")
{
e.Row.Cells[4].Text = "<a href="mailto:" + e.Row.Cells[4].Text + "">" + e.Row.Cells[4].Text + "</a>";
}
//Birthday highlight
if (e.Row.Cells[6].Text != " ")
{
DateTime dt = Convert.ToDateTime(e.Row.Cells[6].Text);
DateTime now = DateTime.Now;
if (dt.Day == now.Day && dt.Month == now.Month)
{
e.Row.Cells[6].BackColor = System.Drawing.Color.FromArgb(255, 230, 160);
}
}
}
}
I use this event to customize the display of certain fields, as well as hide columns that are not pplicable during some search types. When I disable the event, the ODS stops binding twice. I can't really think of a way to get around this behavior. Has anyone else see this issue or developed a work around?
View 1 Replies
Mar 24, 2010
CheckPara is my OnDataBinding procedure SqlDataSource1 is ObjectDataSource (it's only confusing name)
Language is Nemerle, but if you know C# you can read it easy
protected virtual CheckPara(_ : object, _ : System.EventArgs) : void
{
foreach(x is Parameter in SqlDataSource1.SelectParameters)
when(x.DefaultValue=="") //Cancel binding
}
so how can I cancel binding when there is not fully configurated ObjectDataSource ? Or... how can I run binding only when I done with all parameters ?
View 2 Replies