Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Wednesday, March 28, 2012

AJAX Update Panel and DataGrid

I write code to populate a datagrid with a Datatable stores in a session variable, I put some data in text boxes and click ADD button it stores that data in table and assign that table to a session variable. FINE.

When I click a datagrid item to Edit. Occasionally it says "Index is out of bound...". It is not always and not always with every row of datagrid. I click on another row to edit it works fine.

I do not know what is actually going inside AJAX. because of using AJAX my ADD and EDIT functionality do not refreshes the page but update the content as required.

Any body know that what should I do?

Regards,

Ather Ali Shaikh

I had a similar problem. I found that on every command I had to recreate the dataview (what I was using) where I used the info from the dataview then things were fine but if I didn't I would get out of bound errors as well as other weird messages. I wasn't trying to use the edit feature of the GridView but just displaying info when a link in a the GridView was clicked so you may also run into things I've not yet found. Anyway, hope this helps some.

Hi,

I do not use the Edit template of the datagrid, what I am doing is using template columns contains Edit link button and on capture is command click event on datagrid on Command event handler.

Monday, March 26, 2012

AJAX Toolkit CalendarExtender Issue

I am going to write a web application using AJAX Toolkit. In one of the application modules, I have to use calendar control. To meet this requirement I am using CalendarExtender with a TextBox control. I have a problem when I submit the form having this controls combination. The problem is that I am unable to get Text field value after submitting the form. I have written a sample page to make my point cleat to you. Here is the code:


<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
string strDate = "";
strDate = txtCheckinDate.Text;
}

</script>

...

...

<div>

<asp:TextBox ID="txtCheckinDate" runat="server" ReadOnly="True"></asp:TextBox>
<asp:ImageButton ID="btnCalendar" runat="server" AlternateText="Click to show calendar" ImageUrl="~/images/Calendar_scheduleHS.png" />
<div style="font-size: 90%"><em>(Click the image button to open the calendar)</em></div> <br />
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Format="MMMM d, yyyy" PopupButtonID="btnCalendar" Animated="true"
TargetControlID="txtCheckinDate"> </ajaxToolkit:CalendarExtender> <br />

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

</div>


Would you please help me to find out the cause of problem?

Waiting your kind reply.


I created my own...Works for me. I did notice a few thing.

The ScriptManager must appear before any control that needs it.

Your page should include something like this...

<%@. Register Assembly="AjaxControlToolkit, Version=1.0.10301.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

and your tag prefix should look something like this

 <cc1:CalendarExtender ID="CalendarExtender1" runat="server" Format="MMMM d, yyyy" PopupButtonID="btnCalendar" Animated="true" TargetControlID="txtCheckinDate"> </cc1:CalendarExtender>

I hope that helps.

Saturday, March 24, 2012

Ajax timer and update panels

Is there a way that an updatepanel could be set (through an attribute) to ONLY update when something has changed without the need to write custom code?

For example, I have a page with an updatepanel on it that updates its contents every 10 seconds. However, I only want to refresh the data in that update panel when something in it has changed - not every single time the timer fires. The updatepanel has images in it and, because i do not want to display any cached results, I setResponse.CacheControl = "no-cache" and Response.AddHeader("Pragma", "no-cache")on page_init. The end result is screen flicker every 10 seconds).

It would be nice to have the update panel only update if something has changed by comparing the existing and the new data.

suggestions welcome - just email me or post a reply

Dan

Hi,dan.kotarski

I am afraid UpdatePanel cann't do this!

Maybe you can use WebService or PageMethod as an alternative, You can write some JS to compare the existing data and the new data in the result of WebService or PageMethod.

Let me know if you need more info.

Hope this helps.

Thanks!

Ajax Timer and Session Timeout

I want to detect a page with ajax timer to check if the session is timeout. however, the timer will keep the session always ON.
Thus i write a counter to check the session. However the Session variable will be always = 5.
Why ? or is there any other methods to check if the sesison is timout ?

Thanks.

protected

void Page_Load(object sender,EventArgs e)
{
Session.Add("CheckSession", 5);
}protectedvoid Timer1_Tick(object sender,EventArgs e)
{
int j = (int)Session["CheckSession"] - 1;
if (j <= 0)
{
this.Response.Redirect(http://www.google.com);
}
Session["CheckSession"] = j;
}

In page load check for post back.

ie. Session.add cod shouldgo into following block. Currently for each time tick event is calledpag_load also is getting executed and checkSession remains as 5 always.

if(!Page.IsPostBack()){

}

AJAX throw a "Sys.WebForms.PageRequestManagerErrorException" with Server.Transfer

Hi,

First, I′m from Brazil and I don′t know to write English very well, but try show my problem.

I have an application ASP NET AJAX 1.0 with 2 pages in diferent folders, how show the schemma:

Folder 1HomeFolder 2PageWithUpdatePanel

PageWithUpdatePanel contains a UpdatePanel with a Button Control named Button1.

When Home calls PageWithUpdatePanel with Server.Transfer, an error happens in browser when Button1 is pressed in a second time. Any Control causes the exception.

Details from exception message:

Sys.WebForms.PageRequestManagerErrorException: unknown error ocurred while processing the request on the server. The status code returned from the server was: 404

Another message happens with DropDownList:

Sys.WebForms.PageRequestManagerErrorException: The message received from the server cound not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near '<html xmlns="htt'.

I read that "ScriptManager1.RegisterPostBackControl(Button1)" resolves the problem. But is the same that don′t uses Ajax. That result isn′t satisfactory.

With ATLAS the error don′t happens.

The Microsoft Support has resolved the question. Past the Code after UpdatePanel: function EndRequestHandler() { theForm.action = "../NewFolder1/Default.aspx"; theForm._initialAction = theForm.action; } if( typeof(Sys) != "undefined" ) { EndRequestHandler(); Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); }

I have the same issue but I wasn't able to translate the solution from the answer above. Can somebody translate the above answer into VB?

Thank you.


The code is to place in HTML Markup, not in Code-behind. Is JavaScript. The code, with line-breaks is:

function EndRequestHandler()
{
theForm.action = "../NewFolder1/Default.aspx";
theForm._initialAction = theForm.action;
}
if( typeof(Sys) != "undefined" )
{
EndRequestHandler();
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}


Hellooo, I Have the same problem with you, can you help me how to resolve them.

where i can put that code ? can you give me the full source code ?

Thanx And Sorry My English so badBig Smile


No problem, I don′t speak English so mutch too. About the code, you have to place it in HTML markup, after the end tag of UpdatePanel.


I was trying to execute the Server.Transfer([myASPXpage]) inside the click event for my Save button. There were a couple posts on the WEB that poo pooed the idea of using Server.Transfer() in general but for my scenario it ( I thought) was necessary. After the user saved their information I wanted to return them to the main page. On the main page I was using the Request object to verify if the user was coming from a valid URI (make sure the user was signed in). Using Response.Redirect was not helpful because there wasn't a PreviousPage object to check (as there would have been if Server.Transfer was available).

In the end the solution was simple, I had overthunk the scenario by a mile. On my main page I utilized the User object checking the identity to verify that the user was signed in and valid.

Hope that makes sense...