easy ASP.NET question

G

Guest

I have a asp:button wth an event handler, when the event fires I also want to
change the property attribute of a div tag to not visible.

How do I reference the HTML doms named item to set the property ?
I know how with JavaScript on the client with DHTML, but confused now
 
G

Guest

Thanks - seems the asp:panel is the equivalent for design and renders the div
tag. Seems that the HTML DOM is simply not accessible
 
M

Mark Rae

I have a asp:button wth an event handler, when the event fires I also want
to
change the property attribute of a div tag to not visible.

How do I reference the HTML doms named item to set the property ?
I know how with JavaScript on the client with DHTML, but confused now

In your HTML:
<asp:Button ID="MyButton" runat="server" OnClick="MyButton_Click" />

In your server-side code's Page_Load event:
MyButton.Attributes.Add("onclick", "alert('Hello world!)';");

Since you already know how to hide the div with JavaScript, substitute the
alert code with the JavaScript code which hides the div.
 
C

clintonG

That's both right and wrong. Simply remove the div from the HTML. Replace
the div with a Panel control which renders as a div at runtime. In the
button's event handler reference the Panel and set Panel1.Visible = false
noting this requires a PostBack of course.

If you still want to do it at runtime you need to write attributes to the
button at runtime. When the button is clicked it can invoke your JavaScript
function which disables visibility. You can also raise the button's event
handler using JavaScript. Start learning AJAX/Atlas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top