RegisterClientScriptBlock Method

Started by thiruvasagamani, Apr 07, 2009, 11:40 AM

Previous topic - Next topic

thiruvasagamani

RegisterClientScriptBlock Method

Now let's create a better version of the button rollover example by using the RegisterClientScriptBlock method. The problem with the rollover button example from earlier is that when the end user's mouse hovered over the button image, the rollover image had to be retrieved from the server in a separate request. A better rollover button situation would be where the rollover image of the button is already downloaded and stored in the browser's cache so that when the end user hovers over the button, it is instantaneously displayed. To accomplish this we must build a JavaScript function. The following example shows the JavaScript function as well as the use of the RegisterClientScriptBlock method to get the function onto the page. For this example, the code-behind only needs a Page_Load event and a button-click event for an ImageButton server control.

Visual Basic .NET

Private Sub Page_Load(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles MyBase.Load
        Page.RegisterClientScriptBlock("MyScript", _
            "<script language=javascript>" & _
            "if (document.images) {" & _
            "MyButton = new Image;" & _
            "MyButtonShaded = new Image;" & _
            "MyButton.src = 'button1.jpg';" & _
            "MyButtonShaded.src = 'button2.jpg';" & _
            "}" & _
            "else {" & _
            "MyButton = '';" & _
            "MyButtonShaded = '';" & _
            "}" & _
            "</script>")

        ImageButton1.Attributes.Add("onmouseover", _
           "this.src = MyButtonShaded.src;" & _
           "window.status='Oh Yes! Click here!';")
        ImageButton1.Attributes.Add("onmouseout", _
           "this.src = MyButton.src;" & _
           "window.status='';")
End Sub

Private Sub ImageButton1_Click(ByVal sender As System.Object, _
  ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Label1.Text = "Postback!"


Source : MSDN
Thiruvasakamani Karnan



FredagFlemingzb

hi everyone,  I am in the development of finalizing my meaningful beauty buying. I've gone surfing numberless portals and for all timethis meaningful beauty site appears genuine. Anybody have any feedback regarding them?                             
Thanks all for reading.

Quick Reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it has been approved by a moderator.

Name:
Email:
Verification:
Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S post or ALT+P preview