0

A webpage(.aspx) which has a button along with onclick event which was working as expected. But, I'd like to access a div tag (status) at javascript method when I click asp button (btnValidate). My aim is hide/visible div based on the action happened inside code behind event.

How can I do this?

/** My Button Control Definition **/

<div style="top:0px;margin-top:0px;">
<asp:Button ID="btnValidate" runat="server" Text="Renew" 
CssClass="SubmitButton" onclick="btnValidate_Click"  />                     
</div>

/** Div status needs to be accessed in javascript when click asp.net button **/

<div id="status">
  <!-- Some control goes here for status -->
</div>

/** Button code Behind event **/

protected void btnValidate_Click ( object sender, EventArgs e )
{
  /** Some code goes here **/
}

3 Answers 3

2

Either add runat="server" attribute to your div so it's accessible from code behind or put it inside <asp:PlaceHolder> and change visibility of it.

You don't need to use javascript to do this.

Sign up to request clarification or add additional context in comments.

Comments

2

You can use registerstartupscript to run javascript from the codebehind

http://msdn.microsoft.com/en-us/library/bb359558.aspx

for example:

protected void btnValidate_Click ( object sender, EventArgs e )
{
     ScriptManager.RegisterStartupScript(Page, Page.GetType(), "uniqueKey", "FunctionCall();", true);
}

Comments

0

One way would be to add runat="server" and id="[YourDivId]" in your div code. Then place the div and the button in a common update panel.

The you use the div as an asp control in c# (ex: this.YourDivId.Visible = false;)

(There are other ways too.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.