Saturday, March 24, 2012

a sample project using AJAX

Hi,

i am doing a sample project to use Hovermenu extender..i have taken a lablebox whenever i will take mouse over it , it can be editable..but it is showing error

"DynamicControlID must be set"

This is code...

protectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

Label1.Text = DateTime.Now.ToString()

EndSub

ProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click

EndSub

<System.Web.Services.WebMethodAttribute()> <System.Web.Script.Services.ScriptMethodAttribute()>PublicSharedFunction GetDynamicContent(ByVal contextKeyAs System.String)As System.String

EndFunction

<formid="form1"runat="server">

<div>

</div>

<asp:ButtonID="Button1"runat="server"Style="z-index: 100; left: 49px; position: absolute;

top: 200px"Text="Click"/>

<asp:LabelID="Label1"runat="server"Style="z-index: 101; left: 59px; position: absolute;

top: 28px"Text="Label"></asp:Label>

<cc1:ConfirmButtonExtenderID="ConfirmButtonExtender1"runat="server"

TargetControlID="Button1"ConfirmText="R u Sure">

</cc1:ConfirmButtonExtender>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<cc1:HoverMenuExtenderID="HoverMenuExtender1"runat="server"DynamicServiceMethod="GetDynamicContent"

TargetControlID="Label1"PopupControlID="label2">

</cc1:HoverMenuExtender>

<asp:LabelID="Label2"runat="server"Style="z-index: 103; left: 127px; position: absolute;

top: 171px"Text="hi"></asp:Label>

</form>

Kindly check it,

Regards,

Suryansu

To fix the error "DynamicControlID must be set" you should remove the attribute DynamicServiceMethod="GetDynamicContent"

That will solve error.Still then you will not be able to edit the label .To achive the effect you need follow the below script.

For futrher infiormation refer to the below link

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HoverMenu/HoverMenu.aspx

One possible way to implement your requirement is as like below

<form id="form1" runat="server">
<div>
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Hover Me"></asp:Label>
<div runat="server" style="background-color: Yellow; width: 50px; height: 50px" id="popup">
<asp:TextBox ID="txtLabelContent" runat="server"></asp:TextBox>
<asp:Button ID="btnChangeTheLabel" OnClick="btnChangeTheLabel_Click" runat="server" Text="Set the Label Text" />
</div>
<ajaxToolkit:HoverMenuExtender PopupControlID="popup" TargetControlID="Label1" ID="HoverMenuExtender1"
runat="server">
</ajaxToolkit:HoverMenuExtender>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>

in the server side implement this

protected void btnChangeTheLabel_Click(object sender, EventArgs e)
{
Label1.Text = txtLabelContent.Text;
}


If you get an answer to your question, please mark it solved so people don't waste time reading already answered questions!


Thanx

No comments:

Post a Comment