Ask a Question related to ASP.NET General, Design and Development.
-
suzy #1
beginner quesion about IsPostBack
hi,
i have an aspx page with a button. if i step through my code when i click
the button then it calls the button_Click event which is what i want.
but i need to redirect the page to another aspx page when this button is
clicked so i dont want to waste time rendering the same page before
redirecting, so i put the following code in, but now the button_click event
doesn't get called :(
what am i doing wrong? how can i render a page the first time its called,
but if the button is clicked , then immediately call the button_Click event.
private void Page_Load(object sender, System.EventArgs e)
{
if (!(Page.IsPostBack))
{
//perform main rendering of the page here.
}
}
by the way, here is my click event code:
private void button_Click(object sender, EventArgs e)
{
Response.Redirect("anotherpage.aspx";
}
suzy Guest
-
Not IsPostBack
I have a problem. I have a function Load_Info where I am generating dymanic table. On a first load is it fine however after the refresh because it... -
IsPostBack ??
Hi, how can I initialize data kept in the Session-object only the first time a WS is invoked and not everytime the WS is invoked. I tried : ... -
IsPostBack issues??
I have a datagrid in my development environment and it works just fine. I am able to edit and so forth. I moved it to my production environment... -
Composite Controls and Me.Page.IsPostback Problem
Hi all, In my Composite Control's Sub New Function I am unable to check if Me.Page.IsPostback. Me.Page is Nothing (so i get a... -
Manually get the text that a certain control posted when in IsPostBack mode...
I have a page with EnableViewState="false". That page contains a DropDownList with dynamic items and a submit Button. I need to get the... -
suzy #2
Re: beginner quesion about IsPostBack
sorry that was just a typo.
there is no error, it just renders the page, then calls the click event.
"David Wier" <dwier@nospamASPNet101.com> wrote in message
news:u5oZTQrWDHA.536@TK2MSFTNGP10.phx.gbl...click> Do you get an error?
> Try:
> Response.Redirect("anotherpage.aspx");
>
> David Wier
> [url]http://aspnet101.com[/url]
> [url]http://aspexpress.com[/url]
>
>
> "suzy" <suzy@nospam.com> wrote in message
> news:OWDWeLrWDHA.2268@TK2MSFTNGP11.phx.gbl...> > hi,
> >
> > i have an aspx page with a button. if i step through my code when icalled,> event> > the button then it calls the button_Click event which is what i want.
> >
> > but i need to redirect the page to another aspx page when this button is
> > clicked so i dont want to waste time rendering the same page before
> > redirecting, so i put the following code in, but now the button_click> > doesn't get called :(
> >
> > what am i doing wrong? how can i render a page the first time its> event.> > but if the button is clicked , then immediately call the button_Click>> >
> > private void Page_Load(object sender, System.EventArgs e)
> >
> > {
> >
> > if (!(Page.IsPostBack))
> >
> > {
> >
> > //perform main rendering of the page here.
> >
> > }
> >
> > }
> >
> > by the way, here is my click event code:
> >
> > private void button_Click(object sender, EventArgs e)
> >
> > {
> >
> > Response.Redirect("anotherpage.aspx";
> >
> > }
> >
> >
>
suzy Guest
-
makthar #3
beginner quesion about IsPostBack
If you just want to redirect to a different page and not
do anything else you can use hyperlink instead of the
button.
If you are going to be doing something before redirecting
then you have the code for rendering inside a if not
ispostback event so you are not wasting time rendering it
again. Because this will be skipped when the user clicks
on the button.
You can see for yourself by setting break points and
stepping through the code if you are using an IDE.
code when i click>-----Original Message-----
>hi,
>
>i have an aspx page with a button. if i step through mywhat i want.>the button then it calls the button_Click event which isthis button is>
>but i need to redirect the page to another aspx page whenpage before>clicked so i dont want to waste time rendering the samebutton_click event>redirecting, so i put the following code in, but now thetime its called,>doesn't get called :(
>
>what am i doing wrong? how can i render a page the firstbutton_Click event.>but if the button is clicked , then immediately call the>
>private void Page_Load(object sender, System.EventArgs e)
>
>{
>
> if (!(Page.IsPostBack))
>
> {
>
> //perform main rendering of the page here.
>
> }
>
>}
>
>by the way, here is my click event code:
>
>private void button_Click(object sender, EventArgs e)
>
>{
>
> Response.Redirect("anotherpage.aspx";
>
>}
>
>
>.
>makthar Guest
-
William F. Robertson, Jr. #4
Re: beginner quesion about IsPostBack
You might want to consider adding to the onclick attribute for the redirect.
That way it would say the whole postback/redirect.
in the page load
button.Attributes["OnClick"] = "javascript : self.location.href =
'anotherpage.aspx';"
HTH,
bill
"suzy" <suzy@nospam.com> wrote in message
news:OWDWeLrWDHA.2268@TK2MSFTNGP11.phx.gbl...event> hi,
>
> i have an aspx page with a button. if i step through my code when i click
> the button then it calls the button_Click event which is what i want.
>
> but i need to redirect the page to another aspx page when this button is
> clicked so i dont want to waste time rendering the same page before
> redirecting, so i put the following code in, but now the button_clickevent.> doesn't get called :(
>
> what am i doing wrong? how can i render a page the first time its called,
> but if the button is clicked , then immediately call the button_Click>
> private void Page_Load(object sender, System.EventArgs e)
>
> {
>
> if (!(Page.IsPostBack))
>
> {
>
> //perform main rendering of the page here.
>
> }
>
> }
>
> by the way, here is my click event code:
>
> private void button_Click(object sender, EventArgs e)
>
> {
>
> Response.Redirect("anotherpage.aspx";
>
> }
>
>
William F. Robertson, Jr. Guest
-
suzy #5
Re: beginner quesion about IsPostBack
yes i am dynamically creating the button.
i didnt realise this would make a difference , because the click event gets
called if the "if" statement is not there. the downside to this is that it
performs unnecessary actions by rendering the current page before
redirecting.
"Marina" <zlatkinam@nospam.hotmail.com> wrote in message
news:equ$dXrWDHA.652@TK2MSFTNGP10.phx.gbl...it> Are you dynamically creating the button? In which case, you must recreateclick> on postback.
>
> "suzy" <suzy@nospam.com> wrote in message
> news:OWDWeLrWDHA.2268@TK2MSFTNGP11.phx.gbl...> > hi,
> >
> > i have an aspx page with a button. if i step through my code when icalled,> event> > the button then it calls the button_Click event which is what i want.
> >
> > but i need to redirect the page to another aspx page when this button is
> > clicked so i dont want to waste time rendering the same page before
> > redirecting, so i put the following code in, but now the button_click> > doesn't get called :(
> >
> > what am i doing wrong? how can i render a page the first time its> event.> > but if the button is clicked , then immediately call the button_Click>> >
> > private void Page_Load(object sender, System.EventArgs e)
> >
> > {
> >
> > if (!(Page.IsPostBack))
> >
> > {
> >
> > //perform main rendering of the page here.
> >
> > }
> >
> > }
> >
> > by the way, here is my click event code:
> >
> > private void button_Click(object sender, EventArgs e)
> >
> > {
> >
> > Response.Redirect("anotherpage.aspx";
> >
> > }
> >
> >
>
suzy Guest
-
Marina #6
Re: beginner quesion about IsPostBack
There is a difference. You must recreate the button, otherwise your event
will not get called.
"suzy" <suzy@nospam.com> wrote in message
news:%238sA7wrWDHA.3924@tk2msftngp13.phx.gbl...gets> yes i am dynamically creating the button.
>
> i didnt realise this would make a difference , because the click eventit> called if the "if" statement is not there. the downside to this is thatrecreate> performs unnecessary actions by rendering the current page before
> redirecting.
>
>
> "Marina" <zlatkinam@nospam.hotmail.com> wrote in message
> news:equ$dXrWDHA.652@TK2MSFTNGP10.phx.gbl...> > Are you dynamically creating the button? In which case, you mustis> it> click> > on postback.
> >
> > "suzy" <suzy@nospam.com> wrote in message
> > news:OWDWeLrWDHA.2268@TK2MSFTNGP11.phx.gbl...> > > hi,
> > >
> > > i have an aspx page with a button. if i step through my code when i> > > the button then it calls the button_Click event which is what i want.
> > >
> > > but i need to redirect the page to another aspx page when this button> called,> > event> > > clicked so i dont want to waste time rendering the same page before
> > > redirecting, so i put the following code in, but now the button_click> > > doesn't get called :(
> > >
> > > what am i doing wrong? how can i render a page the first time its>> > event.> > > but if the button is clicked , then immediately call the button_Click> >> > >
> > > private void Page_Load(object sender, System.EventArgs e)
> > >
> > > {
> > >
> > > if (!(Page.IsPostBack))
> > >
> > > {
> > >
> > > //perform main rendering of the page here.
> > >
> > > }
> > >
> > > }
> > >
> > > by the way, here is my click event code:
> > >
> > > private void button_Click(object sender, EventArgs e)
> > >
> > > {
> > >
> > > Response.Redirect("anotherpage.aspx";
> > >
> > > }
> > >
> > >
> >
>
Marina Guest
-
suzy #7
Re: beginner quesion about IsPostBack
when you say it worked, do you mean it DIDNT render the main page before
redirecting???
that is what i am trying to prevent... the unnecessary rendering before the
redirection.
"David Wier" <dwier@nospamASPNet101.com> wrote in message
news:uc0kmyrWDHA.1900@TK2MSFTNGP10.phx.gbl...want.> That's really strange - - - I just copied your code to a new file, ran it
> and it worked just fine - - I even added other code...
> Here's the way I did it - - -
>
> <html>
> <head>
> <script language="C#" Runat="server">
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (!(Page.IsPostBack))
> {
> //perform main rendering of the page here.
> ddl.Items.Add("Red");
> ddl.Items.Add("Blue");
> ddl.Items.Add("Green");
> ddl.Items.Add("Purple");
> }
> }
> private void button_Click(object sender, EventArgs e)
> {
> Response.Redirect([url]http://microsoft.com);[/url]
> }
> </script>
> </head>
> <body>
> <form id="form1" Runat="server">
> My text is here<asp:DropDownList id="ddl" Runat="server">
> </asp:DropDownList><p>
> <asp:Button id="button1" Text="click here" onclick="button_Click"
> Runat="server" />
> </form>
> </body>
> </html>
>
> David Wier
> [url]http://aspnet101.com[/url]
> [url]http://aspexpress.com[/url]
>
>
> "suzy" <suzy@nospam.com> wrote in message
> news:uL2GUVrWDHA.2204@TK2MSFTNGP12.phx.gbl...> > sorry that was just a typo.
> >
> > there is no error, it just renders the page, then calls the click event.
> >
> >
> > "David Wier" <dwier@nospamASPNet101.com> wrote in message
> > news:u5oZTQrWDHA.536@TK2MSFTNGP10.phx.gbl...> > click> > > Do you get an error?
> > > Try:
> > > Response.Redirect("anotherpage.aspx");
> > >
> > > David Wier
> > > [url]http://aspnet101.com[/url]
> > > [url]http://aspexpress.com[/url]
> > >
> > >
> > > "suzy" <suzy@nospam.com> wrote in message
> > > news:OWDWeLrWDHA.2268@TK2MSFTNGP11.phx.gbl...
> > > > hi,
> > > >
> > > > i have an aspx page with a button. if i step through my code when i> > > > the button then it calls the button_Click event which is what ibutton> > > >
> > > > but i need to redirect the page to another aspx page when thisbutton_click> is> > > > clicked so i dont want to waste time rendering the same page before
> > > > redirecting, so i put the following code in, but now thebutton_Click> > called,> > > event
> > > > doesn't get called :(
> > > >
> > > > what am i doing wrong? how can i render a page the first time its> > > > but if the button is clicked , then immediately call the>> >> > > event.
> > > >
> > > > private void Page_Load(object sender, System.EventArgs e)
> > > >
> > > > {
> > > >
> > > > if (!(Page.IsPostBack))
> > > >
> > > > {
> > > >
> > > > //perform main rendering of the page here.
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > > by the way, here is my click event code:
> > > >
> > > > private void button_Click(object sender, EventArgs e)
> > > >
> > > > {
> > > >
> > > > Response.Redirect("anotherpage.aspx";
> > > >
> > > > }
> > > >
> > > >
> > >
> > >
> >
>
suzy Guest
-
Marina #8
Re: beginner quesion about IsPostBack
There is no 'rendering'. The original page never makes it back to the
browser.
What does happen, is that you are creating a bunch of objects - there is
some cost associated with that (though not much). Also, if you have database
access, there is cost associated with that as well.
"suzy" <suzy@nospam.com> wrote in message
news:eyWchQsWDHA.2360@TK2MSFTNGP12.phx.gbl...the> when you say it worked, do you mean it DIDNT render the main page before
> redirecting???
>
> that is what i am trying to prevent... the unnecessary rendering beforeit> redirection.
>
> "David Wier" <dwier@nospamASPNet101.com> wrote in message
> news:uc0kmyrWDHA.1900@TK2MSFTNGP10.phx.gbl...> > That's really strange - - - I just copied your code to a new file, ranevent.> > and it worked just fine - - I even added other code...
> > Here's the way I did it - - -
> >
> > <html>
> > <head>
> > <script language="C#" Runat="server">
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > if (!(Page.IsPostBack))
> > {
> > //perform main rendering of the page here.
> > ddl.Items.Add("Red");
> > ddl.Items.Add("Blue");
> > ddl.Items.Add("Green");
> > ddl.Items.Add("Purple");
> > }
> > }
> > private void button_Click(object sender, EventArgs e)
> > {
> > Response.Redirect([url]http://microsoft.com);[/url]
> > }
> > </script>
> > </head>
> > <body>
> > <form id="form1" Runat="server">
> > My text is here<asp:DropDownList id="ddl" Runat="server">
> > </asp:DropDownList><p>
> > <asp:Button id="button1" Text="click here" onclick="button_Click"
> > Runat="server" />
> > </form>
> > </body>
> > </html>
> >
> > David Wier
> > [url]http://aspnet101.com[/url]
> > [url]http://aspexpress.com[/url]
> >
> >
> > "suzy" <suzy@nospam.com> wrote in message
> > news:uL2GUVrWDHA.2204@TK2MSFTNGP12.phx.gbl...> > > sorry that was just a typo.
> > >
> > > there is no error, it just renders the page, then calls the clicki> > >
> > >
> > > "David Wier" <dwier@nospamASPNet101.com> wrote in message
> > > news:u5oZTQrWDHA.536@TK2MSFTNGP10.phx.gbl...
> > > > Do you get an error?
> > > > Try:
> > > > Response.Redirect("anotherpage.aspx");
> > > >
> > > > David Wier
> > > > [url]http://aspnet101.com[/url]
> > > > [url]http://aspexpress.com[/url]
> > > >
> > > >
> > > > "suzy" <suzy@nospam.com> wrote in message
> > > > news:OWDWeLrWDHA.2268@TK2MSFTNGP11.phx.gbl...
> > > > > hi,
> > > > >
> > > > > i have an aspx page with a button. if i step through my code whenbefore> want.> > > click
> > > > > the button then it calls the button_Click event which is what i> button> > > > >
> > > > > but i need to redirect the page to another aspx page when this> > is> > > > > clicked so i dont want to waste time rendering the same page> button_click> > > > > redirecting, so i put the following code in, but now the> button_Click> > > > event
> > > > > doesn't get called :(
> > > > >
> > > > > what am i doing wrong? how can i render a page the first time its
> > > called,
> > > > > but if the button is clicked , then immediately call the>> >> > > > event.
> > > > >
> > > > > private void Page_Load(object sender, System.EventArgs e)
> > > > >
> > > > > {
> > > > >
> > > > > if (!(Page.IsPostBack))
> > > > >
> > > > > {
> > > > >
> > > > > //perform main rendering of the page here.
> > > > >
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > > by the way, here is my click event code:
> > > > >
> > > > > private void button_Click(object sender, EventArgs e)
> > > > >
> > > > > {
> > > > >
> > > > > Response.Redirect("anotherpage.aspx";
> > > > >
> > > > > }
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
Marina Guest
-
suzy #9
Re: beginner quesion about IsPostBack
marina,
you are absolutely right! i just tried it again but this time i added ONLY
the button before the "if" statement in the page_load event. now if i click
the button the button_click event fires without rendering the entire page.
however, it has left my page looking untidy (and in the wrong order too!) as
the button is now at the top of the page, rather than at the bottom!
is there a neat way to get around my problem? it just seems a bit messy :(
thanks again!
"Marina" <zlatkinam@nospam.hotmail.com> wrote in message
news:eWU983rWDHA.2376@TK2MSFTNGP11.phx.gbl...want.> There is a difference. You must recreate the button, otherwise your event
> will not get called.
>
> "suzy" <suzy@nospam.com> wrote in message
> news:%238sA7wrWDHA.3924@tk2msftngp13.phx.gbl...> gets> > yes i am dynamically creating the button.
> >
> > i didnt realise this would make a difference , because the click event> it> > called if the "if" statement is not there. the downside to this is that> recreate> > performs unnecessary actions by rendering the current page before
> > redirecting.
> >
> >
> > "Marina" <zlatkinam@nospam.hotmail.com> wrote in message
> > news:equ$dXrWDHA.652@TK2MSFTNGP10.phx.gbl...> > > Are you dynamically creating the button? In which case, you must> > it> > click> > > on postback.
> > >
> > > "suzy" <suzy@nospam.com> wrote in message
> > > news:OWDWeLrWDHA.2268@TK2MSFTNGP11.phx.gbl...
> > > > hi,
> > > >
> > > > i have an aspx page with a button. if i step through my code when i> > > > the button then it calls the button_Click event which is what ibutton> > > >
> > > > but i need to redirect the page to another aspx page when thisbutton_click> is> > > > clicked so i dont want to waste time rendering the same page before
> > > > redirecting, so i put the following code in, but now thebutton_Click> > called,> > > event
> > > > doesn't get called :(
> > > >
> > > > what am i doing wrong? how can i render a page the first time its> > > > but if the button is clicked , then immediately call the>> >> > > event.
> > > >
> > > > private void Page_Load(object sender, System.EventArgs e)
> > > >
> > > > {
> > > >
> > > > if (!(Page.IsPostBack))
> > > >
> > > > {
> > > >
> > > > //perform main rendering of the page here.
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > > by the way, here is my click event code:
> > > >
> > > > private void button_Click(object sender, EventArgs e)
> > > >
> > > > {
> > > >
> > > > Response.Redirect("anotherpage.aspx";
> > > >
> > > > }
> > > >
> > > >
> > >
> > >
> >
>
suzy Guest
-
suzy #10
Re: beginner quesion about IsPostBack
yes i have database calls during the rendering process, which is why i am
trying to prevent it.
:)
"Marina" <zlatkinam@nospam.hotmail.com> wrote in message
news:ejwmsSsWDHA.1512@TK2MSFTNGP11.phx.gbl...database> There is no 'rendering'. The original page never makes it back to the
> browser.
>
> What does happen, is that you are creating a bunch of objects - there is
> some cost associated with that (though not much). Also, if you havewhen> access, there is cost associated with that as well.
>
> "suzy" <suzy@nospam.com> wrote in message
> news:eyWchQsWDHA.2360@TK2MSFTNGP12.phx.gbl...> the> > when you say it worked, do you mean it DIDNT render the main page before
> > redirecting???
> >
> > that is what i am trying to prevent... the unnecessary rendering before> it> > redirection.
> >
> > "David Wier" <dwier@nospamASPNet101.com> wrote in message
> > news:uc0kmyrWDHA.1900@TK2MSFTNGP10.phx.gbl...> > > That's really strange - - - I just copied your code to a new file, ran> event.> > > and it worked just fine - - I even added other code...
> > > Here's the way I did it - - -
> > >
> > > <html>
> > > <head>
> > > <script language="C#" Runat="server">
> > > private void Page_Load(object sender, System.EventArgs e)
> > > {
> > > if (!(Page.IsPostBack))
> > > {
> > > //perform main rendering of the page here.
> > > ddl.Items.Add("Red");
> > > ddl.Items.Add("Blue");
> > > ddl.Items.Add("Green");
> > > ddl.Items.Add("Purple");
> > > }
> > > }
> > > private void button_Click(object sender, EventArgs e)
> > > {
> > > Response.Redirect([url]http://microsoft.com);[/url]
> > > }
> > > </script>
> > > </head>
> > > <body>
> > > <form id="form1" Runat="server">
> > > My text is here<asp:DropDownList id="ddl" Runat="server">
> > > </asp:DropDownList><p>
> > > <asp:Button id="button1" Text="click here" onclick="button_Click"
> > > Runat="server" />
> > > </form>
> > > </body>
> > > </html>
> > >
> > > David Wier
> > > [url]http://aspnet101.com[/url]
> > > [url]http://aspexpress.com[/url]
> > >
> > >
> > > "suzy" <suzy@nospam.com> wrote in message
> > > news:uL2GUVrWDHA.2204@TK2MSFTNGP12.phx.gbl...
> > > > sorry that was just a typo.
> > > >
> > > > there is no error, it just renders the page, then calls the click> > > >
> > > >
> > > > "David Wier" <dwier@nospamASPNet101.com> wrote in message
> > > > news:u5oZTQrWDHA.536@TK2MSFTNGP10.phx.gbl...
> > > > > Do you get an error?
> > > > > Try:
> > > > > Response.Redirect("anotherpage.aspx");
> > > > >
> > > > > David Wier
> > > > > [url]http://aspnet101.com[/url]
> > > > > [url]http://aspexpress.com[/url]
> > > > >
> > > > >
> > > > > "suzy" <suzy@nospam.com> wrote in message
> > > > > news:OWDWeLrWDHA.2268@TK2MSFTNGP11.phx.gbl...
> > > > > > hi,
> > > > > >
> > > > > > i have an aspx page with a button. if i step through my codeits> i> before> > want.> > > > click
> > > > > > the button then it calls the button_Click event which is what i> > button> > > > > >
> > > > > > but i need to redirect the page to another aspx page when this> > > is
> > > > > > clicked so i dont want to waste time rendering the same page> > button_click> > > > > > redirecting, so i put the following code in, but now the> > > > > event
> > > > > > doesn't get called :(
> > > > > >
> > > > > > what am i doing wrong? how can i render a page the first time>> > button_Click> > > > called,
> > > > > > but if the button is clicked , then immediately call the> >> > > > > event.
> > > > > >
> > > > > > private void Page_Load(object sender, System.EventArgs e)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > if (!(Page.IsPostBack))
> > > > > >
> > > > > > {
> > > > > >
> > > > > > //perform main rendering of the page here.
> > > > > >
> > > > > > }
> > > > > >
> > > > > > }
> > > > > >
> > > > > > by the way, here is my click event code:
> > > > > >
> > > > > > private void button_Click(object sender, EventArgs e)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > Response.Redirect("anotherpage.aspx";
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
suzy Guest
-
suzy #11
Re: beginner quesion about IsPostBack
judging by what marina said in another post in this thread, i think your
page might have worked as you aren't dynamically creating your button.
"David Wier" <dwier@nospamASPNet101.com> wrote in message
news:uc0kmyrWDHA.1900@TK2MSFTNGP10.phx.gbl...want.> That's really strange - - - I just copied your code to a new file, ran it
> and it worked just fine - - I even added other code...
> Here's the way I did it - - -
>
> <html>
> <head>
> <script language="C#" Runat="server">
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (!(Page.IsPostBack))
> {
> //perform main rendering of the page here.
> ddl.Items.Add("Red");
> ddl.Items.Add("Blue");
> ddl.Items.Add("Green");
> ddl.Items.Add("Purple");
> }
> }
> private void button_Click(object sender, EventArgs e)
> {
> Response.Redirect([url]http://microsoft.com);[/url]
> }
> </script>
> </head>
> <body>
> <form id="form1" Runat="server">
> My text is here<asp:DropDownList id="ddl" Runat="server">
> </asp:DropDownList><p>
> <asp:Button id="button1" Text="click here" onclick="button_Click"
> Runat="server" />
> </form>
> </body>
> </html>
>
> David Wier
> [url]http://aspnet101.com[/url]
> [url]http://aspexpress.com[/url]
>
>
> "suzy" <suzy@nospam.com> wrote in message
> news:uL2GUVrWDHA.2204@TK2MSFTNGP12.phx.gbl...> > sorry that was just a typo.
> >
> > there is no error, it just renders the page, then calls the click event.
> >
> >
> > "David Wier" <dwier@nospamASPNet101.com> wrote in message
> > news:u5oZTQrWDHA.536@TK2MSFTNGP10.phx.gbl...> > click> > > Do you get an error?
> > > Try:
> > > Response.Redirect("anotherpage.aspx");
> > >
> > > David Wier
> > > [url]http://aspnet101.com[/url]
> > > [url]http://aspexpress.com[/url]
> > >
> > >
> > > "suzy" <suzy@nospam.com> wrote in message
> > > news:OWDWeLrWDHA.2268@TK2MSFTNGP11.phx.gbl...
> > > > hi,
> > > >
> > > > i have an aspx page with a button. if i step through my code when i> > > > the button then it calls the button_Click event which is what ibutton> > > >
> > > > but i need to redirect the page to another aspx page when thisbutton_click> is> > > > clicked so i dont want to waste time rendering the same page before
> > > > redirecting, so i put the following code in, but now thebutton_Click> > called,> > > event
> > > > doesn't get called :(
> > > >
> > > > what am i doing wrong? how can i render a page the first time its> > > > but if the button is clicked , then immediately call the>> >> > > event.
> > > >
> > > > private void Page_Load(object sender, System.EventArgs e)
> > > >
> > > > {
> > > >
> > > > if (!(Page.IsPostBack))
> > > >
> > > > {
> > > >
> > > > //perform main rendering of the page here.
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > > by the way, here is my click event code:
> > > >
> > > > private void button_Click(object sender, EventArgs e)
> > > >
> > > > {
> > > >
> > > > Response.Redirect("anotherpage.aspx";
> > > >
> > > > }
> > > >
> > > >
> > >
> > >
> >
>
suzy Guest
-
Rajeev Soni #12
Re: beginner quesion about IsPostBack
Solution for ur problems is based on ur requirement:
1. If you need to do some processing on the server when the button is clicked before transfering the control to another page, then u dont have any option ur page will get build and ......... and after that ur button click event will be fired. (pl. go thru asp.net page life cycle).
2. If u dont want to do any processing on the server when the button is clicked the just add OnClick attribute as said by william.
button.Attributes["OnClick"] = "javascript : self.location.href ='anotherpage.aspx';"
rajeev
"suzy" <suzy@nospam.com> wrote in message news:uS90l34WDHA.1268@TK2MSFTNGP11.phx.gbl...> anyone have a solution to this?
>
> "suzy" <suzy@nospam.com> wrote in message
> news:Op%23t8TsWDHA.536@TK2MSFTNGP10.phx.gbl...> ONLY> > marina,
> >
> > you are absolutely right! i just tried it again but this time i added> click> > the button before the "if" statement in the page_load event. now if i> as> > the button the button_click event fires without rendering the entire page.
> >
> > however, it has left my page looking untidy (and in the wrong order too!)> :(> > the button is now at the top of the page, rather than at the bottom!
> >
> > is there a neat way to get around my problem? it just seems a bit messy> event> >
> > thanks again!
> >
> >
> > "Marina" <zlatkinam@nospam.hotmail.com> wrote in message
> > news:eWU983rWDHA.2376@TK2MSFTNGP11.phx.gbl...> > > There is a difference. You must recreate the button, otherwise your> that> > > will not get called.
> > >
> > > "suzy" <suzy@nospam.com> wrote in message
> > > news:%238sA7wrWDHA.3924@tk2msftngp13.phx.gbl...
> > > > yes i am dynamically creating the button.
> > > >
> > > > i didnt realise this would make a difference , because the click event
> > > gets
> > > > called if the "if" statement is not there. the downside to this is> i> > > it
> > > > performs unnecessary actions by rendering the current page before
> > > > redirecting.
> > > >
> > > >
> > > > "Marina" <zlatkinam@nospam.hotmail.com> wrote in message
> > > > news:equ$dXrWDHA.652@TK2MSFTNGP10.phx.gbl...
> > > > > Are you dynamically creating the button? In which case, you must
> > > recreate
> > > > it
> > > > > on postback.
> > > > >
> > > > > "suzy" <suzy@nospam.com> wrote in message
> > > > > news:OWDWeLrWDHA.2268@TK2MSFTNGP11.phx.gbl...
> > > > > > hi,
> > > > > >
> > > > > > i have an aspx page with a button. if i step through my code when> before> > want.> > > > click
> > > > > > the button then it calls the button_Click event which is what i> > button> > > > > >
> > > > > > but i need to redirect the page to another aspx page when this> > > is
> > > > > > clicked so i dont want to waste time rendering the same page>> > button_click> > > > > > redirecting, so i put the following code in, but now the> > button_Click> > > > > event
> > > > > > doesn't get called :(
> > > > > >
> > > > > > what am i doing wrong? how can i render a page the first time its
> > > > called,
> > > > > > but if the button is clicked , then immediately call the> >> > > > > event.
> > > > > >
> > > > > > private void Page_Load(object sender, System.EventArgs e)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > if (!(Page.IsPostBack))
> > > > > >
> > > > > > {
> > > > > >
> > > > > > //perform main rendering of the page here.
> > > > > >
> > > > > > }
> > > > > >
> > > > > > }
> > > > > >
> > > > > > by the way, here is my click event code:
> > > > > >
> > > > > > private void button_Click(object sender, EventArgs e)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > Response.Redirect("anotherpage.aspx";
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>Rajeev Soni Guest



Reply With Quote

