i am using < div onclick=”””> to call the server side .How can i avoid full page refresh when user click the < div>?
Here is my coding.
HTML
<asp:UpdatePanel ID="updatePanel1" runat="server"> <ContentTemplate>
<div id ="cde" runat="server" style="background-color: #00FFFF" > </div>
<asp:Label ID="Label1" runat="server" Text="Label"> </asp:Label>
</ContentTemplate> </asp:UpdatePanel>
Server side
protected void Page_Load(object sender, EventArgs e)
{
//--Register for div onclick function --
cde.Attributes["onclick"] = ClientScript.GetPostBackEventReference(this, "divMember_Click");
//**Register for div onclick function**
}
protected void divMember_Click()
{
this.Label1.Text = System.DateTime.Now.ToString();
}
public void RaisePostBackEvent(string eventArgument)
{
if (!string.IsNullOrEmpty(eventArgument))
{
if (eventArgument == "divMember_Click")
{
divMember_Click();
}
}
}
I try putting the label within the update panel . But postback will still occur. How can i refresh the label without full page reload?
you can use Jquery .ajax function or pagemethod.YourWebMethod.
Create Web Method in your C# Code and call it using these two functions.
You can do Page Method by EnabledPageMethod=”true” in script Manager and use Jquery .ajax function put jquery java script.
This will be on page behind code (create Web Method):
return DateTime.Now.ToString();
As referenced in Default.aspx, this is java script: