|
You should learn to use const s
What's the difference?
ViewState["conut"]
ViewState["count"]
If you spell things properly, it works better. If you use const s to store the names of things in your viewstate the compiler will tell you when you mistype stuff so you can see where you are going wrong quicker.
|
|
|
|
|
Try with this.No need of global variable.
protected void Button1_Click(object sender, EventArgs e)<br />
{<br />
if (ViewState["Count"] == null)<br />
ViewState["Count"] = 0;<br />
int newCount = (int)ViewState["Count"] + 1;<br />
ViewState["Count"] = newCount;<br />
txtCount.Text = newCount.ToString();<br />
}
Arun J
|
|
|
|
|
But there is a problem .->ON every click , ViewState["Count" ] start with null value,i wnat textbox display the number of clicks....but it remain shows "1".........
|
|
|
|
|
Did u try with that code i posted?It'll work fine.Viewstate can't be null from the second click onwards.Just copy and paste that code and Check again...It'll work..
Arun J
|
|
|
|
|
Yes...i used your methode....but there still problem.......ok i try again
thanks
|
|
|
|
|
Just Debug the application and see what is stored in the viewstate when post back occures
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
zeeShan anSari wrote: else
{ j = (int)ViewState["count"] + 1; }
ViewState["count"] = j;
}}
try the below logic...
protected int J = 0;
protected void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
else
J = Viewstate["Count"];
}
protected void Page_PreRender(object sender, System.EventArgs e)
{
ViewState["Count"] = J;
}
protected void Button1_Click(object sender, System.EventArgs e)
{
J = J + 1;
TxtBox.Text = J;
}
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
|
|
|
|
|
private int Foo
{
get { return ViewState["Foo"] as int? ?? 0; }
set { ViewState["Foo"] = value;
}
Then go play with your Foo.
|
|
|
|
|
yes!..I get the solution......which are as:
public partial class _Default : System.Web.UI.Page<br />
{<br />
protected int j=0;<br />
<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
<br />
<br />
if (!IsPostBack)<br />
{<br />
ViewState["count"] = 0;<br />
<br />
}<br />
<br />
}
protected void Button3_Click(object sender, EventArgs e)<br />
{<br />
<br />
<br />
<br />
j =(int) ViewState["count"];<br />
j = j + 1;<br />
TextBox4.Text = "" + j;<br />
ViewState["count"] = j;<br />
<br />
}<br />
}
|
|
|
|
|
Hi,
I have a cookie generated in the JavaScript(using document.cookie). How can i access this in the cs page. Request.Cookies[CookieName] does not work.
Regards,
Rahul Babu
|
|
|
|
|
Hii,
Could any one please tell me how to insert values from dynamic text boxes using C# code.
Actually i have to create more and more dynamic text boxes whenever a user clicks on more button, and also i want to fetch the values from these text boxes and store it into the database. Could any one please tell me how i will do this.
Actually until and unless form will not get loaded the controls will not be created at run time, then how i will get the id of the text boxes so that i can write the code.
Any help will be appreciated.
Thanks
Imran
|
|
|
|
|
Think on this might be helpfull
Create a user control with all texboxes that you have to add at runtime.
Now the user control should contains one property/method that will accept a object. These object is nothing but the class object that you are going to store in session.Every time you will have to update session and UI Fields
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
ASP.NET won't maintain viewstate for the controls created after viewstate load event has been fired. You can use DataGrid/GridView to do this. Put your controls inside a template column and add each row to the DataGrid when button is pressed. Use FindControl() to find the control from grid.
|
|
|
|
|
Create the dynamic control on the Page Init event, so that the control will participate in the Viewstate. You will be able to read the contents as you normally do with static texboxes. This article may help you through...Dynamic Controls[^]
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
|
|
|
|
|
Am suggesting a simple way.Declare a static variable count in the page.While creating textbox give the ID of the textbox as count+1;
when u need the data for saving,iterate through for loop by using the count variable and find the control using this count as ID.
Arun J
|
|
|
|
|
Creating a static variable will give problem nothing than else
what for another user ? this count is going to be share by them also
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
If static variable will cause problem,then just use viewstate.It'll work fine.
Arun J
|
|
|
|
|
Dear Programmers,
I am facing a new problem. I have imports to files
imports system.data
imports system.data.sqlclient
I have also added reference of these two files through Add References.
It show me their classes but when i execute the application it gives me the error at those places where i have used object of the above mentioned classes.
Please help me in this regard. what shall i do to get rid of it?
Waiting for your replys
|
|
|
|
|
I don't know where we can use import keyword in C#. Might be you are developing your application VB rather than C# then you are at wrong place. Place correct forum for this.
Again verify those dll should present in your application.
Add these dll to your project then import where you want to use them
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
playing with bugs ) wrote: I don't know where we can use import keyword in C#.
Imports statement is used to import namespaces in VB.NET. I think Using is the equivalent in C#.NET.
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
|
|
|
|
|
Can you please post the details of the exceptions you are recieving.
Thanx...
Clean code is the key to happiness.
|
|
|
|
|
protected void Menus_MenuItemClick(object sender, EventArgs e)
{
//string x=(string) e.Item.Value;
MenuItemCollection m = new MenuItemCollection();
//System.Web.UI.WebControls.MenuEventArgs x = e.ToString();
}
i want to know which item of the menu is click .
please let me know .
|
|
|
|
|
The 2nd argument for the event handler should be of type MenuEventArgs . You can reference the selected item from the information exposed by this type.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
hi all
while running my application am getting an error like this :-
Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Source Error:
Line 38: by Microsoft that offers a single logon and core profile services for member sites.
Line 39: -->;
Line 40: <authentication mode="Windows">;
Line 41:
Line 42:
can u say wht might be the problem?
|
|
|
|
|
Did you try Google to find out what the error message means?
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|