easy ASP.NET question

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Thanks - seems the asp:Panel is the equivalent for design and renders the div
tag. Seems that the HTML DOM is simply not accessible
 
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.
 
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.
 
Back
Top