Showing posts with label sub. Show all posts
Showing posts with label sub. Show all posts

Monday, March 26, 2012

Execute javascript doesnt work for popup calendar in AJAX

Hi I create a popup calendar and put the following code for clicking on calendar:

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
PopupControlExtender1.Commit(Calendar1.SelectedDate.ToShortDateString())
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "setCursor", "alert(777);", True)
End Sub

Page.ClientScript.RegisterClientScriptBlock will cause javascript executed auto when I clicking on popup calendar. It works for ATLAS. But after I moved it to AJAX, it doesn't work. no response for this javascrpt.

Help please.

With ASP.NET AJAX Beta, you need to move to ScriptManager.RegisterClientScriptBlock instead of Page.ClientScript.RegisterClientScriptBlock.

Thanks. David.

But for my case, ScriptManager is put in master page. And the following code is put inside a user control (.ascx) and loaded dynamically.

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
PopupControlExtender1.Commit(Calendar1.SelectedDate.ToShortDateString())
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "setCursor", "alert(777);", True)
End Sub

How to get ScriptManager object in user control?


I changed the code as:

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
PopupControlExtender1.Commit(Calendar1.SelectedDate.ToShortDateString())
Dim sm As Microsoft.Web.UI.ScriptManager
sm = Page.Master.FindControl("MasterScriptManager")
sm.RegisterClientScriptBlock(Me.Page, Me.GetType(), "setFocus", "alert(777);", True)
End Sub

it still doesn't work. Help please.



The Control parameter to RegisterClientScriptBlock (the first param) needs to specify a control that's inside the UpdatePanel that's being updated when the script block is to be updated. I suspect that Me.Page in your example does not satisfy that requirement, so please try a control that does.
Thank you so much, David.

Saturday, March 24, 2012

Exclude page_load during ajax content pannel update possible?

I have this in my behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(String.Format("{0:yyyy}", DateTime.Now).ToString()))
End Sub

The problem is, whenever I select a new value in my drop down list, it defaults itself back to the current month. Is there a way to exclude this from running when I am using an ajax update panel?

You can use Page.IsPostback for this. It is false for the very first request, and true for any postback (also true for async postback)

If you need to determine whether you have a full or an async postback, you can use:IsInAsyncPostBack


If anyone was curious as to how the syntax looked here it is. Worked like a charm. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Page.IsPostBack = False) Then DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(String.Format("{0:yyyy}", DateTime.Now).ToString())) End If End Sub