Showing posts with label project. Show all posts
Showing posts with label project. Show all posts

Wednesday, March 28, 2012

Accessing controls in a tab control using javascript

Hi ,

Im my project im using tab control.I wat to access the controls inside the content template using javascript.

How is this done?

Anyone please help.

Thanks n regards

Prathibha

prathibhaa:

Im my project im using tab control.I wat to access the controls inside the content template using javascript.

You need to know the client id of the control you want to access. You can get the client id of the control using the ClientID property.

Then in javascript you do this

document.getElementById(<id of control>) to get reference to the control


i tried it.

I have a textbox "txtEmpCode" placed in the content template of tab control.then i tried to access it as follows

document.getElementById("txtEmpCode")

But im getting null value


prathibhaa:

I have a textbox "txtEmpCode" placed in the content template of tab control.then i tried to access it as follows

document.getElementById("txtEmpCode")

Because the text box is in the tab control it may get a different client ID. Best way to check is to view the HTML source on the rendered page and look for the exact ID.

Alternatively you can go textbox.ClientID to get the client rendered ID of the text box control.


i tried this code

document.getElementById("<%=txtEmpCode.ClientID%>")

But I am getting an exception

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Description:Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.

Exception Details:System.Web.HttpException:The Controls collection cannot be modified because the control containscode blocks (i.e. <% ... %>).

Source Error:

An unhandled exception was generated during the execution of thecurrent web request. Information regarding the origin and location ofthe exception can be identified using the exception stack trace below.


Stack Trace:

[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.Add(Control child) +127
AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) in d:\E\AjaxTk-AjaxControlToolkit\Release\AjaxControlToolkit\ExtenderBase\ScriptObjectBuilder.cs:293
AjaxControlToolkit.ScriptControlBase.OnLoad(EventArgs e) in d:\E\AjaxTk-AjaxControlToolkit\Release\AjaxControlToolkit\ExtenderBase\ScriptControlBase.cs:260
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Control.LoadRecursive() +158
System.Web.UI.Control.LoadRecursive() +158
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3036

Please help

Thanks and regards

prathibha


prathibhaa:

i tried this code

document.getElementById("<%=txtEmpCode.ClientID%>")

But I am getting an exception

Where are you adding that code to?

You can always just inject the javascript doing this

StringBuilder sb =new StringBuilder();sb.Append("function getTextBox()");sb.Append("{");sb.Append("var textbox;");sb.Append("textbox = document.getElementById();");sb.Append("return textbox;");sb.Append("}");ClientScript.RegisterClientScriptBlock(this.GetType(),"mytextboxscript", sb.ToString());//now you have a javascript function that returns the textbox




Hi Prathibha,

prathibhaa:

document.getElementById("<%=txtEmpCode.ClientID%>")

But I am getting an exception

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

That's because you put the document.getElementById("<%=txtEmpCode.ClientID%>") in the wrong position. For example,

<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function getName(){

var labelValue = "<%=Label1.ClientID %>";
}
</script>
</head>

<body>
You will get the same error. So you should put it at the end of your form(or other proper position). By the way, you can use$get instead of document.getElementById() if you have added a ScriptManager before. They are the same but is much terser.

Best regards,

Jonathan


hi Jonathan,

Thank you.

can u please tell me where i have to give the javascript and how?

i got the javascript correctly when i gave the client id directly.

regards

Prathibha

Saturday, March 24, 2012

about AjaxToolKit project page

a question really remotely related to the AtlasToolkit, but I did not know where else to ask: the bug tracking and work item tracking that you have there is really nice, what is that for a system? Homemade or somewhere available?

It'sCodePlex, Microsoft's public project management system.

Abort AJAX Postback

Hello,

I am developing a project, which has many things on admin and merchant side, but very less on user site.

The user site contains a page from where user can search the data. This is the main page on user site.

The search page contains 10 sliders and 6 different parameters which are checkboxlist. There are at least 5, 00,000 records in the database.

I am using database paging to get result fast.

I am using AJAX on this page.

Now the problem is that when ever I move the slider and release it then button click event is called from JavaScript.

I have 10 sliders on the page now when I move all the sliders one by one the page becomes very slow. It performs all the post backs in the queue.

Is there any way from which I can cancel the previous post back if the page is already inasynchronous postback.

I have even tried the following code when the user moves the slider; I call the following function;

function StopPostBack()

{

var CheckPostBack = Sys.WebForms.PageRequestManager.getInstance();

if (CheckPostBack.get_isInAsyncPostBack())

{

CheckPostBack.abortPostBack();

}

}

But this too not helped me much.

I think the problem is that when ever user moves the first slider and release it the button click event is called and in that the stored procedure is called to fetch the data.

Now when user move another slider the function StopPostBack is called but till that time the application has started the database operation.

My stored procedure taking less then 2 sec to return the data. But when there are multiple movements of the slider the page is very slow.

How can I make is fast.

Regards,

Deepesh Verma

Hi Deepesh,

Please refer to this thread, http://forums.asp.net/thread/1695055.aspx
There is no easy way to abort the execution on the server from the client.
I think you need to find a way to reduce the occurrence of postback on the client.

A widget framework

I am currently embarking on a project to deliver content via a mini portal for students at a community college.

What I would like to do is build a framework which works the same way as iGoogle, PageFlakes, Live.com or any other site which allows you to mash up your own start page.

Are there any frameworks or projects underdevelopment which will demonstrate the patterns involved in creating "Widgets" that you can include on a page just by adding a <script src="http://pics.10026.com/?src=APPLICATIONSRC"></script>

I have a couple working models where I use the external script to write innerHTML to a div where the script tag is included, but there is much more work to do and I was wondering if anyone has any ideas on the best / most resuable way to accomplish this.

For all backend data we will be using standard web services decorated with the [ScriptMethod] and [ScriptService] attributes.

Here is the code i've got working so far:

 initWidgetContainer(); initWidget(); function initWidgetContainer() { var wc = $get("WidgetContainer_1");if (wc ==null) { document.write("<div id='WidgetContainer_1' class='widgetcontainer'>Add widgets here</div>"); } } function initWidget() { SunGard.Public.Services.ERP.InitWidget(initComplete); } function initComplete(result) { Render(result); } function LoadData(widgetObj) { SunGard.Public.Services.ERP.LoadProfile(widgetObj,"lucasstark", Render); } function Render(result) {//Write the contanier to push the data into. var wc = $get("WidgetContainer_1"); wc.innerHTML = wc.innerHTML + result.WidgetContainer;//Now that we have our container set up for us, lets write some content into it; $get(result.WidgetID).innerHTML = result.WidgetContent; }
 
//Here is the asmx service
//Partial listing:
 
 [WebMethod]public Widget InitWidget() { Widget w =new Widget(); w.WidgetID = Guid.NewGuid().ToString(); w.LoadWidgetData();return w; }

// and finally partial of the widget

/// <summary>/// Summary description for Widget/// </summary>public class Widget{private string _widgetID;private string _widgetContent;public string WidgetID {get {return _widgetID; }set { _widgetID =value; } }public string WidgetContent {get {return _widgetContent; }set { _widgetContent =value; } }public string WidgetContainer {get {return"<div id = '" + WidgetID +"' class=\"widgetdata\"></div>"; } }public Widget(){ }private void SetOutput(string innerData) {this._widgetContent = innerData; }public void LoadWidgetData() {#region Datastring data = @." <h2>Lucas Stark</h2> <table> <tr> <td> Full Name: </td> <td> Lucas Stark </td> <td> </td> </tr> <tr> <td> Email Address: </td> <td> <a href='mailto:lucasstark@.delta.edu'>lucassatrk@.delta.edu</a> </td> <td> </td> </tr> <tr> <td> Phone Number: </td> <td> 9541 </td> <td> </td> </tr> </table>";#endregion SetOutput(data); }


Checkout this articlehttp://www.codeproject.com/Ajax/MakingGoogleIG.asp


Thanks for the link.

I've played around with and reviewed the code for that applicaiton before, but it seems WAY overly complex. I thought there used to be a slimmed down version of that which wasn't using DLINQ or workflow to acomplish the same things, but I can't seem to locate it..

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

Wednesday, March 21, 2012

A high level ATLAS implementation question.

Hello, we are looking into this technology for a project currently in design.

The project is comparable to a browser based chat application so for the purpose of this post I will use a chat example.

  • Five users join a chat session
  • One person types a message and sends it to the group
  • The list of chat messages is updated for each user.

    Let's say the app needs to scale to 10,000 users and the messages are stored in a database and managed on the server.

    We could use Atlas to send the message to the server when the user clicks Send – this works great. My dilemma is how to update each client with the new chat message. We have considered using a timer on the client and polling the server using Atlas for new messages. However, this seems inefficient and doesn't scale due to our capacity requirements and all the net traffic this could produce.

    Is there a way to employ more a broadcast model using the Atlas technology? Could we use an Event in the server code that makes anOnCompletecallback to each cleint who's joined the session? Is there another way to message from the server to multiple clients?

    Thanks in advance for any advice you can provide, links, documentation, examples, etc...

    Kind Regards.

    Sounds like you should use a "Broadcast Pattern".
    ie.
    - all active users become part of some "active user broadcast list" as they join a chat session
    - then some class/thread is invoked to broadcast the message to all users in the list
    In between or after you can store the message in a db or whatever.
    dev


    Dev, thanks for the response.

    Yes, the broadcast pattern is along the lines we're thinking. The question is how to implement this model.

    I imagine we could wire up an Event in the server code that would fire when there's a new message submitted by any client.

    How then would the server broadcast the message to each of the web clients who are participating (up to 10000). Could an individual thread be kept alive somehow on the server for each client? This is where we were thinking about the OnComplete logic supported by Atlas. It seems like there's an AJAX solution out there somewhere for this.

    Thanks in advance for any more advice.


    Hi Bill,

    Here is how you could implement your chat s/w:

    Server side:
    Create the below webmethods:
    1. UpdateMe_async()
    polls the db for new messages. When new messages are available it returns an array of messages and client ids.
    2. ReceiveMsg(messagestring, clientid, otherparams...)
    Receives and adds the message to the db.

    Client side:

    Do the following:
    Onload:
    Make an async call to UpdateMe_async() webmethod. Set the call back to a function say func_UpdateMe().
    func_UpdateMe()
    Displays messages.
    On send button click:
    Make a call to the ReceiveMsg() webmethod.


    Hope it helps!

  • A ContentTemplate must be specified for UpdatePanel

    Why has the Update Panel been changed in the new release so that a ContentTemplate must be specified. In my project i'd like to dynamically add controls to the panel in a user control.

    Is this something that that is permanent?

    Do not confuse the ASP.NET Panel control with the ASP.NET "Atlas"UpdatePanel.The ASP.NET "Atlas"UpdatePanel is a new control able to do partial rendering

    In typical ASP.NET 2.0 applications, when a postback occurs, the page is re-rendered. This causes the page to flash in the browser. On the server, during postback, the page lifecycle executes. This ultimately raises the control event that caused the postback and runs the event handler (for example, a Button control's Click handler).

    The ASP.NET "Atlas"UpdatePanel control eliminates the full page refresh. TheUpdatePanel control is used to mark a region in the page that will be updated when a postback occurs, but without the traditional postback behavior in the client. On the server, the page still handles the postback and runs normally, such as raising event handlers. But during the final rendering of the page, only the regions defined byUpdatePanel controls are created. This is referred to aspartial rendering.

    Hope this helps

    Irinel


    I have a webpart server control class that i have extended. i'd like to add a update panel around the contents of the webpart so i can derive from this new class which has all the functionaly of webpart but its contents is with in an update panel.

    I'd this like to add webparts derived from this extended class and add them dynamically to page via database.

    I was having problems with the fact that u can not directly add controls to an update panel by adding controls i've solved this problem by deriving a class from ITemplate and then adding the template to the content template of the update panel.

    I now have the problem the following problem

    "The UpdatePanel 'Update' was not present when the page's InitComplete event was raised. This is usually caused when an UpdatePanel is placed inside a template. "

    which i'm not saw how to resolve.

    I've had success with a update panels dynamically around dynamically added webpartzones with in the onpreint event.

    Any help would be appreciated.

    Thanks

    Paul