The plan for this is when postback is true then save
all fields (value) into the database. If this is the
case, is there a way I can identify that the event
came from the Image button or the submit button?
Chris Andrada
--- Ben Miller <[EMAIL PROTECTED]> wrote:
> Just remember that the Page_Load code is
> specifically for page related
> things. Events like when you click the image button
> are meant to do
> something when you click them.
>
> The image button by default causes a submit
> (postback) so that is the nature
> of the beast.
>
> If you want things to happen specifically when you
> click the button then you
> would be better off doing this type of thing>
>
> private void Page_Load(object sender,
> System.EventArgs e){
> if (Page.IsPostBack)
> {
> lblMessage.Text = "hello";
> }else if (!Page.IsPostBack) {
> // Initialize the page with any values you want
> to do like making the
> calendar invisible
> bDateCalendar.Visible = false;
> }
> }
> private void btnCalendar_Click(object sender,
> System.Web.UI.ImageClickEventArgs e)
> {
> DateTime datNow = DateTime.Now;
> string today = datNow.ToString("d");
> txtBDate.Value = today;
> bDateCalendar.Visible = true;
> }
>
> Events are supposed to be used when you do something
> on the page and it
> posts back. What I use the Page.IsPostBack for is
> to detect that it has NOT
> posted back and then I get a datasource and databind
> my controls. Then when
> it is a PostBack, then I do not bind them because my
> event code rebinds them
> with correct stuff.
>
> Make sense?
>
> Ben Miller
> This post and code are provided "AS IS" and provides
> no warranties, express
> or implied.
>
> ----- Original Message -----
> From: "christopher andrada" <[EMAIL PROTECTED]>
> To: <[email protected]>
> Sent: Tuesday, December 21, 2004 11:18 AM
> Subject: RE: [AspNetAnyQuestionIsOk] How to prevent
> Image Button from
> triggering IsPostBack
>
>
> >
> > Hi Rajendra,
> >
> > I have the following code behind.
> > private void Page_Load(object sender,
> System.EventArgs
> > e){
> > if (Page.IsPostBack)
> > {
> > lblMessage.Text = "hello";
> > }else if (!Page.IsPostBack) {
> > DateTime datNow = DateTime.Now;
> > string today = datNow.ToString("d");
> > txtBDate.Value = today;
> > }
> > }
> > private void btnCalendar_Click(object sender,
> > System.Web.UI.ImageClickEventArgs e)
> > {
> >
> > bDateCalendar.Visible = true;
> > }
> >
> > When i click on the image button, It executes
> > (Page.IsPostBack) and not (!Page.IsPostBack) and
> shows
> > the calendar. If I take out the (Page.IsPostBack)
> > everything works fine. I understand that
> Page_Load is
> > triggered if i click on the image button and I
> only
> > want to triger (Page.IsPostBack) if i click on the
> > Submit button. Please help. Thanks
> >
> > Chris Andrada
> >
> > --- Rajendra Appalla <[EMAIL PROTECTED]>
> > wrote:
> >
> >> For any postback event, the Page_Load event runs.
> >> Only after this, the
> >> corresponding event is handled.
> >>
> >> So if you have an event btnCalendar_Click wired
> to
> >> the button, then
> >> first Page_Load runs, then this event
> >> btnCalendar_Click gets executed.
> >>
> >>
> >> If you do not want some code inside the Page_Load
> >> event not run for
> >> postbacks, then you need to put that inside an if
> >> condition that checks
> >> for postback as:
> >> If ( ! IsPostBack)
> >> {
> >> }
> >>
> >> If your problem is that the event
> btnCalendar_Click
> >> is not getting
> >> executed, check to see whether the event is
> properly
> >> wired to the
> >> button. If not, then go to the design part of
> the
> >> aspx page and double
> >> click your button to wire the button to its
> event.
> >>
> >> Hope this helps.
> >>
> >> Rajendra.
> >>
> >>
> >> _____
> >>
> >> From: christopher andrada
> >> [mailto:[EMAIL PROTECTED]
> >> Sent: Tuesday, December 21, 2004 12:17 PM
> >> To: [email protected]
> >> Subject: [AspNetAnyQuestionIsOk] How to prevent
> >> Image Button from
> >> triggering IsPostBack
> >>
> >> Hi All,
> >>
> >> The following code below is an image button that
> >> triggers the visibility of the calendar and
> populate
> >> the text box with the chosen date. However, if I
> >> click on the image button, IsPostBack is getting
> >> triggered located at Page_Load(). This button is
> >> suppose to trigger another function called
> >> btnCalendar_Click. Please advise on what i'm
> >> suppose
> >> to do. Thanks.
> >>
> >> <td width="442"><INPUT class="input2"
> id="txtBDate"
> >> disabled type="text" size="30" name="txtBDate"
> >> runat="server">
> >>
> <asp:imagebutton
> >> id="btnCalendar"
> >> runat="server"
> >> ImageUrl="images/b_calendar.gif"
> >> ImageAlign="AbsMiddle"
> >>
> >> CausesValidation="False"
> >>
> Autopostback="False"></asp:imagebutton><asp:calendar
> >> id="bDateCalendar" runat="server"
> >> DayNameFormat="FirstLetter" BorderStyle="Solid"
> >>
> >> BackColor="GhostWhite"
> >> BorderColor="Gainsboro"
> >> Visible="False" ShowGridLines="True">
> >>
> >> <SelectorStyle
> >> BorderColor="Maroon"></SelectorStyle>
> >>
> >> <DayHeaderStyle
> >> BackColor="Peru"></DayHeaderStyle>
> >>
> >> <OtherMonthDayStyle
> >> BackColor="Tan"></OtherMonthDayStyle>
> >>
> >> </asp:calendar></td>
> >>
> >>
> >>
> >> __________________________________
> >> Do you Yahoo!?
> >> The all-new My Yahoo! - Get yours free!
> >> http://my.yahoo.com
> >>
> >>
> >>
>
=== message truncated ===
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/