Hi All,
My requirement is like displaying random advertisements in masterpage. I had a page with Ajax Timer control which on Timer_Tick event fetches me a new image and bind to <asp:hyperlink>, my problem is on page_load also i want to display image, but image is displayed only on Timer_Tick after some fixed 3000 seconds is elapsed. On page_load i want to display same images, my images are dynamic comes from database, i store them in a dataset, and binds to asp:hyperlink on timer_tick. Can anyone help, on how to display image on page_load, is there any way how i can attach the server side event (Timer_Tick) on page_load also, so that it will fetch me the image.
Thanks In Advance,
Karthikeyan.
You could invoke your Timer_Tick method from within your Page_Load method. The following example assumes your asp:Hyperlink is called "adLink" and that your AJAX Timer is called adTimer.
To be more thorough, I am performing a check on the first load of the page (not subsequent post backs) to see if the adLink has not had it's url or Image url specified... as such, make sure you deliberately leave these attributes empty when you define your asp:Hyperlink in your aspx page.
1protected void Page_Load(object sender, EventArgs e)
2{
3if (!Page.IsPostBack)
4 {
5// Initialise the ad for first load (if needed).6if (adLink.NavigateUrl.Equals(string.Empty) && adLink.ImageUrl.Equals(string.Empty))
7 {
8 adTimer_Tick(adTimer,null);
9 }
10 }
11}
1213protected void adTimer_Tick(object sender, EventArgs e)
14{
15// Your current code that specifies the ad image and url.16}
Hope this helps,
Tones.
Hi Tony,
Thanks for your valuable reply, my solution is solved, but i had a question, where, my code looks like this,
Public lobjDSetDataAs DataSet -> Global Dataset
Page_Load()
pvGetBannerImages -> This function will go query the images and get the images from the database.
If Not Page.isPostBack Then
pvShowImages() -> This function will get image one by one for a fixed ajax timer intereval 3000 seconds, and binds the image to hyperlink
End if
In aspx, my updatepanel will be like this,
<asp:UpdatePanelID="pnlBanner"runat="server"UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTriggerControlID="Timer1"/>
</Triggers>
<ContentTemplate>
<asp:HyperlinkID="hplAdImage"runat="server"Target="_blank">
<asp:ImageID="BannerImage"runat="Server"/>
</asp:Hyperlink>
<asp:HiddenFieldID="hdCount"runat="Server"/>
</ContentTemplate>
</asp:UpdatePanel>
My Problem is every time, the control is going to If Page.IsNotPostback, and querying the database, i don't want to query the database again, and getting the data back, binding to hyperlink after fixed 3000 milliseconds, is there any way through which i can avoid this database query, sometimes i am getting error like HTTP 500 error with Sys.Exception something like this. Can you help me on this, i thought of using caching but with ajax, is it possible, even if it possible, i had around 8 modules, where this banner will rotate, for each section different banner comes from database, i don't want to cache because it is dynamic data, can i use here SqlCacheDependency, if so can you guide me how to go on this,
Thanks In Advance,
karthikeyan.
No comments:
Post a Comment