|
|
thanks for ur help....i understand the flow.
tbhattacharjee
|
|
|
|
|
|
i got a sample code from a site. onething i just do not understand regarding how value is added in viewstate automatically.
private Dictionary<Guid, string> Names
{
get { return (Dictionary<Guid, string>)ViewState["Names"]; }
set
{
ViewState["Names"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var names = new Dictionary<Guid, string>
{
{Guid.NewGuid(), "John"},
{Guid.NewGuid(), "Smith"},
{Guid.NewGuid(), "Arther"},
{Guid.NewGuid(), "Hari"}
};
ViewState.Add("Names", names);
}
}
protected void btnAddSave_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
Names.Add(Guid.NewGuid(), txtNewName.Text);
}
}
in page load event i understand that few values has been added in Dictionary collection and after that the whole collection is added in viewstate named "Names".in btnAddSave_Click event the code Names.Add(Guid.NewGuid(), txtNewName.Text); adds name again in collection. but one things i just do not understand that how new value is added in viewstate. if someone look private Dictionary Names property there is no any setter so how automatically new value is added in viewstate. i hope my question is clear. in simple word i just want to know there no any setter but then how new values has been added in viewstate when the code goes like "Names.Add(Guid.NewGuid(), txtNewName.Text);". automatically how new values has been added in viewstate. because new values is added in dictionary collection but there is no code available where all dictionaly values added in viewstate after adding any value to the dictionary collection.i run the code and it works fine.so this code become very ambiguous for me. so please help me to understand how new values is added in viewstate when any new values is added in dictionary collection. thanks
tbhattacharjee
|
|
|
|
|
The sample isn't very successful as a basic explanation of accessing viewstate through a method. This is because it adds a dictionary to ViewState, making the code more complicated to understand, as the viewstate iteslf is a a dictionary so you have to workout whether you are dealing with the Viewstate dictionary, or the dictionary inside it. Adding a dictionary to viewstate *is* a pukka thing to do, but it also confuses the explanation IMO. Worse the code adds a new GUID as the key,but doesn't store it on the server side, so it is effectively useless as a key . Take this simplified code, which just stores an integer:
const string MyKey="MeaningOfLife"
private int MeaningOfLife
{
get { return (int)ViewState[MyKey]; }
set { ViewState[MyKey] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
ViewState.Add("Names", names);
}
protected void btnFoo_Click(object sender, EventArgs e)
{
if (Page.IsValid)
Label1.Text= MeaningOfLife;
}
You only need to add the value once (here before postback): it is available in subsequent postbacks as it is in the viewstate object. The property really just wrappers up accessing the Viewstate dictionary key a bit more neatly than direct access. In your sample code Names.Add(Guid.NewGuid(), txtNewName.Text); the Names property gets the Dictionary added in the page load event, the Add method is called on it to store the new value in the Dictionary inside the [viewstate] Dictionary.
|
|
|
|
|
u have given code like this
const string MyKey="MeaningOfLife"
private int MeaningOfLife
{
get { return (int)ViewState[MyKey]; }
set { ViewState[MyKey] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
ViewState.Add("Names", names);
}
protected void btnFoo_Click(object sender, EventArgs e)
{
if (Page.IsValid)
Label1.Text= MeaningOfLi
where u wrote the line like this ViewState.Add("Names", names);
what is names here. no entity found in ur code called names.
what u were trying to do.
my question was
private Dictionary<Guid, string> Names
{
get { return (Dictionary<Guid, string>)ViewState["Names"]; }
}
setter was not there but when Names.Add(Guid.NewGuid(), txtNewName.Text); this line execute it automatically add the new dictionary value in viewstate. i just want know how it is possible. plzz expain.
tbhattacharjee
|
|
|
|
|
Firstly, there is no need to re-iterate my code, it just makes your post long. You also need really to style up your code block if you have any, posts are difficult to read otherwise just highlight the code and click the button that looks like
code block
above the text
Tridip Bhattacharjee wrote: Names.Add(Guid.NewGuid(), txtNewName.Text)
This line does not add to the ViewState directly. it adds to the Dictionary object added in this
code:
var names = new Dictionary<Guid, string>{ };
ViewState.Add("Names", names);
You access the object you added through the property property, which wrappers up the viewstate calls.
Honestly,you need to try out my code first, it's simpler (it won't do what you want, but it demonstrates what is going on much better) set breakpoints and see what is happening. The Dictionary within viewstate example you have found is confusing because, if the reader hasn't got to grips with viewstate, he/she needs to figure out whether the "Add" code is adding to the ViewState Dictionary (it isn't), or the Dictionary item inside the viewstate (it is).
|
|
|
|
|
Hi
I have a JQuery date mask, but when I run the page it throws an error "Microsoft JScript runtime error: Object doesn't support this property or method".
Now, the control that this particular JQuery is meant to be working is added dynamically to a repeater control. Through this, I have looked at the ids of the control, where it was breaking and stopping in Visual Studio and what is being shown on the aspx page. The ids are identical except of the "#" that JQuery has at the start, which is not on the page.
In my JQuery code I have:
JQuery(function ($) {
$('#<%=date.ClientID %>').mask("99/99/9999");
});
Is there away to tell JQuery not to include the "#" when finding the control? I have used UniqueID but this changes any underscore into "$", which is not the same as what is on the page. My only problem is with "#" sign at the start of the ID. I have even added an alert box to check that textbox was there and it came back as null. I have tried even adding a CssClass attribute to the textbox, but this through the same error, too.
Please note that the custom user control that has the textbox is added programatically to the repeater.
Can anyone help?
Thanks
modified on Saturday, December 4, 2010 4:21 AM
|
|
|
|
|
No you can't eliminate the #, its how JQuery identifies element IDs. It sounds as though the getting the element isn't the problem, its the mask function. Are you sure you have included the proper javascript links on your page?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
This is how I have the code set up on the control, as you can see I have the JQuery function commented until I can understand and solve what is going wrong!
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MaskControl.ascx.cs" Inherits="Prototype.CommonControls.MaskControl" >
<asp:textbox id="date" runat="server" width="136px" cssclass="dateMask">
|
|
|
|
|
And $('.dateMask') is a valid element?
Have you tried
$(document).ready()
{
$('.dateMask').mask("99/99/9999");
});
It doesn't have anything to do with the problem but you should place the javascript in a seperate file rather than in the control. It will improve the maintainability of your code.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
The code I am using is from a website called "http://digitalbush.com/projects/masked-input-plugin" and I followed was given on the site. As shown below:
JQuery(function ($) {
$('#<%=date.ClientID %>;').mask("99/99/9999");
});
When I followed the example given on the website, all I was getting is the Microsoft JScript error message. Then I have tried all various ways with CssClass. I will try the example you have given, but I can't try it until Monday. Should it not work, what other advice can you give for me to try?
|
|
|
|
|
That is the problem with just copying code without understanding it.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi
Well, I applied the following code, and added some more:
$(document).ready()
{
$('.dateMask').mask("99/99/9999");
});
To check that JQuery was picking up the ids of the control, I added $('input[class$=dateMask]') and sent the output to an alert box. Thankfully JQuery found the control by class, but fell over when applying the mask. So, the problem lies with the plugin!
|
|
|
|
|
Alert boxes are not debugging tools. You have the source, set a break point and debug.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I placed a listview on my page:
<div id="resultList">
<asp:ListView ID="lstResults" runat="server">
<LayoutTemplate>
<table id="Table1" runat="server" class="TableCSS">
<tr id="Tr1" runat="server" class="TableHeader">
<td id="Td1" runat="server">
Merchant Name
</td>
</tr>
<tr id="ItemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="ItemCSS">
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Title")%>'>
</asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</div>
and I'm binding it like this:
private void loadList()
{
categoryID = (int)Session["categoryID"];
zipCode = Session["zipCode"].ToString();
merchants = TDCBizObj.GetMerchantsByQuery(categoryID, zipCode);
lstResults.DataSource = merchants;
lstResults.DataBind();
}
When I run the page, I see the merchant titles, but the rows are not 'selectable'. They look like labels, not list items. I mean, when I click a row, it doesn't highlight. What am I doing wrong?
Everything makes sense in someone's mind
|
|
|
|
|
The row doesn't highlight on click because you have not told it to do so. You must add some JavaScript to the row element that handles the onClick event and highlights the row as desired.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
when i am opening a 3.5 related web project then Ajax extension is showing i mean script manager,update panel etc but when i am opening 2.0 web project then Ajax extension is not showing. so please guide me what to do if i want Ajax extension should available in case of 2.0 related project when i will open it through VS2008. do i need to download any path if so then please tell me URL from where i can download Ajax extension for 2.0. please help urgent.
thanks in advance.
tbhattacharjee
|
|
|
|
|
in .NET 3.5, Ajax is integragated with the webproject but in .NET 2.0, one need to install the ajax extensions and tool kit if want to use.
you can get the extension from here
|
|
|
|
|
thanks u very much.
tbhattacharjee
|
|
|
|
|
Your welcome
|
|
|
|
|
hi guys. i want to store value in session to keep it between postbacks. after page is changed i don't need value anymore. is there a way to kill session on current page i am, before redirect (changing url)? i dont want to use ViewState.
void Page_Load()
{
if(!Page.IsPostBack)
{
Session["something"] = true
}
}
void Page_LoadComplete()
{
bool something = Session["something"] as bool;
}
|
|
|
|
|
You can use
Session.Remove("something");
wherever you want.
|
|
|
|
|
Am I understanding you correctly, that you need the value to be part of the session as long as the user is using PostBack, but on a new page load, the session value should be empty?
If that is the case, then you can do this simply like this
void Page_Load()
{
if(!Page.IsPostBack)
{
Session["something"] = true;
}
else
{
Session["something"] = false;
}
}
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Hi, I have a interview next week and I have been told there is a test to:
"The technical test will involve creating a SQL server database, importing data into the database and writing a programme to extract data using SQL and C# and ASP.NET."
Can anybody who has set or taken something similar please advise what I can expect here?
I am thinking the data may be in a flat file or excel spreadsheet and I would need to use DTS or import it via the SQL Server wizard? The extract bit, I would guess is either displaying the results on a web page or writing code to extract it to an excel file?
Thanks in advance!

|
|
|
|