Reply
Raise custom event with
Old 07-01-2007, 10:16 AM Raise custom event with
Junior Talker

Posts: 4
Name: Karen Tse
I have a full custom server control with javascript embedded.

In short it will list out images and when an image is selected, it will be displayed as the first image at the top. And this top image can be collapsed and expanded when clicked.

I am very confused how to raise a custom event when an image is clicked. And how to return two string arguments to the client via the event arguments of the event (index number of the item selected, and a short description of item).

A snippet from RenderContents. Will post the rest of the code upon request.

Code:
   Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)
        output.WriteLine("<script language=javascript>                          ")
        output.WriteLine("function CollapseExpand() {                              ")
        output.WriteLine("var div = document.getElementById(div01);    ")
        output.WriteLine("if (div.style.display != 'none') {                         ")
        output.WriteLine("div.style.display = 'none';                                 ")
        output.WriteLine("} else {                                                              ")
        output.WriteLine("div.style.display = '';                                         ") ' or = block
        output.WriteLine(" }}                                                                      ")

        'output.WriteLine("var top;                                                              ")
        'output.WriteLine("function SetDefault(i) {                                      ")
        'output.WriteLine("var img = document.getElementById(i);            ")
        'output.WriteLine("if (img.src != top.src') {                                      ")
        'output.WriteLine("img.src = 'none';                                                 ")
        'output.WriteLine("} else {                                                                ")
        'output.WriteLine("div.style.display = '';                                          ") ' or = block
        'output.WriteLine(" }                                                                         ")

        output.WriteLine("}</script>                                                       ")

        'image at the top
        output.AddAttribute(HtmlTextWriterAttribute.Src, TopImageUrl)
        output.AddAttribute(HtmlTextWriterAttribute.Onclick, "CollapseExpand()")
        output.RenderBeginTag(HtmlTextWriterTag.Img)
        output.RenderEndTag() 'end img

        output.AddStyleAttribute(HtmlTextWriterStyle.Top, "100")
        output.AddStyleAttribute(HtmlTextWriterStyle.Left, "100")
        output.AddStyleAttribute(HtmlTextWriterStyle.Width, "100")
        output.AddStyleAttribute(HtmlTextWriterStyle.Height, "500")
        output.AddStyleAttribute(HtmlTextWriterStyle.Padding, "5")
        output.AddStyleAttribute(HtmlTextWriterStyle.Overflow, "hidden") ' for scrollbar use "auto"
        output.AddStyleAttribute(HtmlTextWriterStyle.Display, "none")
        output.AddAttribute("id", "div01")
        output.RenderBeginTag(HtmlTextWriterTag.Div)

        'add the remaining images
        Dim item As Object
        Dim i As Byte
        For Each item In imageurl
            output.WriteLine("<br>")
            output.AddAttribute(HtmlTextWriterAttribute.Src, imageurl.Item(i))
            'output.AddAttribute("Onmouseover", "Inform()")
            'output.AddAttribute("Onmouseout", "UnInform()")
            'output.AddAttribute(HtmlTextWriterAttribute.Onclick, "SetDefault(this)")
            'output.AddAttribute(HtmlTextWriterAttribute.Id, i.ToString)
            output.RenderBeginTag(HtmlTextWriterTag.Img)
            output.RenderEndTag() 'end img

            i += 1

            'Dim s1 As New SelectEventArgs
            's1.ItemNoArg = i
            's1.DescArg = imagedescription.Item(i)
            'Me.TopImageUrl = imageurl.Item(i)
            'OnSelectedChanged(s1)

        Next

        output.RenderEndTag() 'end div
    End Sub
Thanks for viewing. And would appreciate any help.

Last edited by kt_sc : 07-01-2007 at 10:17 AM. Reason: forgot to add in a few lines.
kt_sc is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Reply     « Reply to Raise custom event with
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12835 seconds with 12 queries