|
if the page number =1 ,link button should be disable.
if the page number =2 ,link button should be enable.
i tried
linkbutton.enabled=false. this is not working.
plz guide me.
|
|
|
|
|
Well can you display your if statement so we can see what is happening, there could be a number of reasons.
What event is your code in?
|
|
|
|
|
This is my code
protected void lnkPrevious_Click(object sender, EventArgs e)
{
if (this.PageNumber ==1)
{
lnkPrevious.Enabled = false;
lnkNext.Enabled = true;
Response.Redirect("pge1.aspx");
}
else
{
this.PageNumber -= 1;
Response.Redirect( "pge"+this.PageNumber.ToString()+".aspx");
}
}
|
|
|
|
|
kathyani wrote: this.PageNumber -= 1;
why have you got a '-' in front of the '='?
|
|
|
|
|
iam having 11 pages.
iam in 7th page.
if i click previous btn it will go to 6th page .thats why i put
this.pagenumber-=1;
|
|
|
|
|
kathyani wrote: Response.Redirect("pge1.aspx");
What is page1.aspx?
If it is the current page, Then It will be depend upon the design of the page(if you are not not set the enabled property at design time,by default it will be enabled).
So
kathyani wrote: lnkPrevious.Enabled = false;
Disable your link button, but
kathyani wrote: Response.Redirect("pge1.aspx");
will Enable it.
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
iam having 1 to 11 link buttons.
if i click 1 button previous button should be disable.
if i move 2 nd button it should be enable.
|
|
|
|
|
Try this, First redirect then disable the button.
protected void lnkPrevious_Click(object sender, EventArgs e)
{
if (this.PageNumber ==1)
{
Response.Redirect("pge1.aspx");
lnkPrevious.Enabled = false;
lnkNext.Enabled = true;
}
else
{
this.PageNumber -= 1;
Response.Redirect( "pge"+this.PageNumber.ToString()+".aspx");
}
}
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
above code is not working..
thanks ..
|
|
|
|
|
Ya,I'm really sorry, It wont work.
Try this in your page load
if(this.PageNumber ==1)
lnkPrevious.Enabled = false;
else
lnkPrevious.Enabled = true;
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
its working.
Thanks a lot...
|
|
|
|
|
i have one problem..
iam getting error .plz guide me .
public partial class PagerControl : System.Web.UI.UserControl
{
private int _pageNumber;
public int PageNumber
{
set
{
_pageNumber = value;
ViewState["PageNumber"] = value;
}
get
{
return int.Parse(ViewState["PageNumber"].ToString());
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (this.PageNumber == 1)
{
lnkPrevious.Enabled = false;
}
else
{
lnkPrevious.Enabled = true;
}
if (this.PageNumber == 11)
{
lnkNext.Enabled = false;
}
else
{
lnkNext.Enabled = true;
}
}
Server Error in '/ucnew' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 22: get
Line 23: {
Line 24: return int.Parse(ViewState["PageNumber"].ToString());
Line 25: }
Line 26: }
|
|
|
|
|
problem is :
You are calling PageNumber in this line ---> if (this.PageNumber == 1) before you have set the value. So you are getting that error. Set the value first then you must do a get.
To Fix this:
Write a contructor of your class and inside the constructor set the value of _pageNumber = 1 or 0 as per your requirement.
sample code here!!!
public PagerControl()
{
_pageNumber = 1;
}
Thanks,
Arindam D Tewary
|
|
|
|
|
Hi arindam ..
i didnt get .
plz guide me in code level ..
|
|
|
|
|
i did'nt get.
plz tell me clearly..
|
|
|
|
|
Just copy the code part I have given !!
public PagerControl()
{
_pageNumber = 1;
}
after this line .
public partial class PagerControl : System.Web.UI.UserControl
{
private int _pageNumber;
So that it looks like:
public partial class PagerControl : System.Web.UI.UserControl
{
private int _pageNumber;
public PagerControl()
{
_pageNumber = 1;
}
Thanks,
Arindam D Tewary
|
|
|
|
|
ITS GIVING A ERROR ,
class,structs,interface method must have a return type.
|
|
|
|
|
it looks like the viewstate page number has not been created yet which is why its showing an object refrerence error as yoiu arent referencing anything!
|
|
|
|
|
kathyani wrote: if (this.PageNumber == 1)
{
You are retrieving the PageNumber before setting it.So
kathyani wrote: return int.Parse(ViewState["PageNumber"].ToString());
Will be null.
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
|
Are you using the user control in all of your 11 pages?
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
yes , iam using all 11 pages
|
|
|
|
|
Why can't you set the pagenumber property at the design time itself(for the user control).I mean In the 11 pages.
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
|
|
|
|
|
i took the previous ,next link buttons and 11 link buttons .
where i have to put pagenumber property ?
|
|
|
|
|
which one i have to put ?
pagenumber =11 (everypage)
or
page1.aspx ,pagenumber =1 ???
|
|
|
|