Showing posts with label user. Show all posts
Showing posts with label user. Show all posts

Wednesday, March 28, 2012

Asp.net ajax in Custom Control

I'm beginner in asp.net ajax.

Now I have to writecustom control and apply machanismpartial updating(which can be applied for User Control)

Could I can applyasp.net ajax forCustom Controlor not , and how to do this ?

Thanks a lot !

Thank you very much !

In fack UpdatePanel can be added to Custom Control !

But I have one problem more !

For creating Custom Control Im using the command in Console

csc /t:library /out:MGR.dll /r:System.dll /r:System.Web.dllMGR.cs

MGR is the name of Custom Control class

after compiling I got the error "the type or namespace name 'UpdataPanel' could not be found (are you missing directive or an assembly referrence?)"

I modified the command to

csc /t:library /out:MGR.dll /r:System.dll /r:System.Web.dll /r:Microsoft.Web.Atlas.dll MGR.cs

but got the same error !

I don't know why ? do you know why this error occured ?

HTD


I dont know exactly what your control will be doing, but all you should need to do is design the whole control in an asp.net ajax update panel.


My goal is "Partial Updating" in Control(which include TextBox and GridView). How you can add Update Panel in Custom Control ??

(In User Control, it's easy to do )


Open your Control.ascx file.

Drag and drop a update panel on to your page.

Select everything but the update panel.

Drag and drop your selection into the update panel.

That's everything you need to do to set up the control.

Anytime you use your control in your application, make sure you have the "Script Manager" Ajax extension on that page.


My deverloping Control is Custom Control, it's not User Control !

HTD


You should b eable to add it like any other control... ?

UpdatePanel panel = new UpdatePanel();

etc.


you can add a custom control class to a updatepanel like this

myControl ctrl =new MyControl();UpdatePanel1.ContentTemplateContainer.Controls.Add(ctrl);

Monday, March 26, 2012

ASP.Net AJAX and Yahoo User Interface

Can any body let me know why to use AJAX.NET instead of YUI library? Is there any added advantages?

Hi,

Microsoft ASP.NET AJAX enables you to quickly create Web pages that include a rich user experience with responsive and familiar user interface (UI) elements. ASP.NET AJAX provides client-script libraries that incorporate cross-browser ECMAScript (JavaScript) and dynamic HTML (DHTML) technologies, and it integrates them with the ASP.NET 2.0 server-based development platform. By using ASP.NET AJAX, you can improve the user experience and the efficiency of your Web applications.

ASP.NET AJAX consists of client-script libraries and of server components that are integrated to provide a robust development framework. In addition to ASP.NET AJAX, you can use the ASP.NET AJAX Control Toolkit and the features in the ASP.NET AJAX Futures releases, which are both community supported.

ASP.NET AJAX Architecture include ASP.NET AJAX Server Architecture rather than only client script.

For more information,go tohttp://www.asp.net/ajax/documentation/live/Overview/default.aspx

The Yahoo! User Interface (YUI) Library is a set of utilities and controls, written in JavaScript, for building richly interactive web applications using techniques such as DOM scripting, DHTML and AJAX. The YUI Library also includes several core CSS resources.

Anyway,if you use ASP.NET to develop Web2.0 application, you'd better use MS AJAX.

Best Regards,

Saturday, March 24, 2012

asp.net ajax

Hello, We have Visual Studio 2003, if we are now interesting in the advantage of asp.net ajax to improve user experience in our web applications, what do we have to do? I guess change VS 2003 to VS 2005, Am I rigth, what else?

If you want to use ASP.NET AJAX you must indeed change to vs2005. There are a several other frameworks that you can use with vs2003. For a detailed list check out:

http://www.ajaxdiff.com/Default.aspx?filter=dotnet

I Like the Anthem toolkit because the complete AJAX Functionality is build i server controls.


You certainly have to upgrade to VS2005 or Visual Web Developer to take the full advantage of Asp.net Ajax. But in case if you still want to stuck with VS 2003 checkout this posthttp://geekswithblogs.net/rashid/archive/2007/07/21/Asp.net-Ajax-and-VS2003.aspx

asp.net 2.0 | urgent | "Cancel" response from client side

hi, I have a web site where user provide some search criteria and click on button "Search". I want to provide a "Cancel" button which user can click. In case search takes long, user clicks on Cancel and he remains on the same page without any result. basically i want to provide the option of cancelling a request already fired or not wait for result of already fired request. I want to do this on client side.

I have tried sample provided on Microsoft site by using PageRequestManager.getinstance(), but it is very slow. http://asp.net/AJAX/Documentation/Live/tutorials/CancelAsyncPostback.aspx

Even in this sample, clicking on cancel does not immediately cancel the query.There is time lag which is almost the same time as when normal response comes back. If I click Cancel, I would expect that search to cancel and same page to get reloaded faster.

Please help me, this is urgent.

Thanks

Seehttp://mattberseth.com/blog/2007/06/aspnet_ajax_canceling_an_async_1.html

-Damien


Thanks Damien for providing linkSmile

It's really helpful


Hi,

I did some research, but I couldn't find anyone complaining about this issue.

As far as I know, the simplest way to cancle a AyncPostback is to use PageRequestManager.getinstance()(http://asp.net/AJAX/Documentation/Live/tutorials/CancelAsyncPostback.aspx), I nerver heard anyone complain that it is too slow.

I don't think there is a better way by now.

So please double check your code.

Best Regards,


Hi Jin,

Thanks for providing the link. I have used Sys.WebForms.PageRequestManager.getInstance().abortPostBack() in my code to cancel the asyn postback. I think it gets cancelled but the problem is that since request is still executing at server, anything that i now do on my application becomes very slow like loading another page or something. and after a few seconds everything returns to normal. this is probably because requests are getting queued at server...


Tirath.g@.hotmail.com:

I think it gets cancelled but the problem is that since request is still executing at server, anything that i now do on my application becomes very slow like loading another page or something. and after a few seconds everything returns to normal

I believe you are correct.

You can try to use the UpdateProgress control to "blank" out the screen while the process is occuring which may stay while the cancel is in progress. You can make the UpdateProgress "modal" so that it blanks out the page; there is an example here:http://blogs.visoftinc.com/archive/2007/09/10/modalupateprogress.aspx

-Damien

Wednesday, March 21, 2012

asp 2.0 Login control and Ajax RC1

Hi to all,

I'm new to ASP & AJAX, but I would like to use Ajax in a Login control, so the page wouldn't refresh for everytime a user log in.

Somehow, even with a very simple code, i can't get this to work. Any idea why this is happening ??

I'm also using a SQL Connection, if needed i'll post here the web.config file

Any help will be greatly apreciated. Thanks

Here goes the code, it can't get any simpler than this ... i guess

<formid="form1"runat="server"><asp:ScriptManagerID="ScriptManager1"runat="server"/><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:LoginID="Login1"runat="server"BackColor="#F7F7DE"BorderColor="#CCCC99"BorderStyle="Solid"BorderWidth="1px"Font-Names="Verdana"Font-Size="10pt"><TitleTextStyleBackColor="#6B696B"Font-Bold="True"ForeColor="#FFFFFF"/></asp:Login></ContentTemplate></asp:UpdatePanel></form>

I don't use <asp:Login,

but try add: EnablePartialRendering="true" to your scriptmanager and UpdateMode="Conditional" to your UpdatePanel.

Hope it works.


Hi,

Unfurtunatly no, everything remains the same, but thanks for your help.

Regards,

ASP .NET Ajax, Windows Authentication and 401.1

Hi all!

I have a website on IIS with Windows Authentication only. Website uses UpdatePanel.

Scenario:

- some user is authenticated on site and browses it

- at some moment his password in Active Directory is changed

- after that user clicks somewhere on site (UpdatePanel tries to update its content)

- user sees Windows Authentication form, enters his login and incorrect password and then press OK three times

- he receives dialog with error message "Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occured while processing the request on the server. The status code returned from the server was: 401".

How to handle this error on the client? How can I redirect user to error page?

For now I found some simple solution. I just suppress error and refresh page.

<asp:ScriptManager

ID="ScriptManager1"

runat="server">

</asp:ScriptManager>

<scripttype="text/javascript"language="javascript">

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function EndRequestHandler(sender, args)

{

if (args.get_error() != undefined)

{

args.set_errorHandled(true);location.reload(true);

}

}

</script>


Thanks a lot.

It is also a solution for all PageRequestManagerServerErrorException- Problems.

(12031, 12030, ...)

ASCX Custom Events and AsyncPostBackTrigger

I have written a user control that raises an event based on certain criteria. I have placed an UpdatePanel around a grid that needs to be updated when that event fires. So I placed a asp:AsyncPostBackTrigger in the Triggers section. I have set the EventName equal to the event from the user control. In my user control, I throw an exception if something is wrong with some of the data. If the exception is thrown, the event does not get called. I would expect a full postback to occur if the event is not triggered (not a partial render from AJAX); however, even if the event is not thrown and the button is clicked, a partial postback occurs anyways. I need to show that the exception happened in the user control, but I cannot wrap the user control in an UpdatePanel since the data is huge and would take awhile to partial postback.

Any suggestions?

hello.

i think this is an old know issue:

http://msmvps.com/blogs/luisabreu/archive/2006/09/26/Quick-tip_3A00_-using-UserControl-events-as-triggers.aspx


Hmmm.. I have tried implementing your solution, but I cannot seem to get it to work. Here is a code snippet what I am doing.

public delegate void PassengerEmployeeSubmittedEventHandler(object sender, PassengerEmployeeSubmittedEventArgs e);

public class PassengerEmployeeSubmittedEventArgs : EventArgs
{

// properties go here
}

UserControlCode
{

public event PassengerEmployeeSubmittedEventHandler PassengerEmployeeSubmitted;

protected virtual void OnPassengerEmployeeSubmitted(PassengerEmployeeSubmittedEventArgs e)
{
if (this.PassengerEmployeeSubmitted != null)
PassengerEmployeeSubmitted(this, e);
}
}

protected void ibtnSubmitEmployee_Click(object sender, ImageClickEventArgs e)
{

If(verified)
OnPassengerEmployeeSubmitted(new PassengerEmployeeSubmittedEventArgs());
else

this.litError.Text = "Error";

}

} // end user control

Web Page Containing Control Code {

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanelPassengers" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ucAddPassengerEmployee" EventName="PassengerEmployeeSubmitted" />
</Triggers>
<ContentTemplate>

// gridview code only

</ContentTemplate>
</UpdatePanel>
<uc1:AddPassengerEmployee ID="ucAddPassengerEmployee" runat="server" />

}

I have tried registering the ImageButton with the RegisterAsyncPostBackControl, but here's what's happening. The UpdatePanel only refreshes when that event is fired, that works, but it still does a Partial Page Update; therefore, if I catch that exception, the literal is never refreshed since it's only doing a partial postback. I would expect it to do a regular postback all the time unless that event is triggered. Any suggestions?


hello again.

it was an old sample, so i've just updated it for the current release:

A.ASCX

<%@. Control Language="C#" ClassName="A" %>

<script runat="server">
private object aux = new object();
public event EventHandler BtClicked
{
add
{
this.Events.AddHandler(aux, value);
}
remove
{
this.Events.RemoveHandler(aux, value);
}
}

void h(object s, EventArgs e)
{
OnBtClicked(e);
}

protected void OnBtClicked(EventArgs a)
{
if (this.Events[aux] != null)
{
((EventHandler)(this.Events[aux]))(this, a);
}
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ScriptManager manager = ScriptManager.GetCurrent(this.Page);
if (manager != null)
{
manager.RegisterAsyncPostBackControl(bt);
}
}
</script>

<asp:Button runat="server" ID="bt" Text="Submit" OnClick="h" UseSubmitBehavior="false" />

PAGE.ASPX

<%@. Page Language="C#" %>

<%@. Register src="http://pics.10026.com/?src=A.ascx" tagname="A" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:ScriptManager runat="server" ID="manager"></asp:ScriptManager>
<asp:UpdatePanel runat="server" id="panel">
<ContentTemplate>
<%=DateTime.Now %>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="A1" EventName="BtClicked" />
</Triggers>
</asp:UpdatePanel>
<uc1:A ID="A1" runat="server" />
</form>
</body>
</html>

the important thing is the call to the RegisterAsyncPostbackControl method


Hello Luis,

I tried using that code and it still doesn't seem to work. I even took your code and made one modification to it. As it is, it works as expected, but if I comment out the call to raise the event in the protected void OnBtClicked(EventArgs a), a partial post back still occurs, and that is the problem I am experiencing. I would expect that if this event is not raised, then a partial postback should NOT occur regardless if the button was clicked; however, please correct me if I am wrong. Thank you very much for your help. What do you think?


hello.

the registerXXX method is responsible for configuring the client page so that it always starts a partial postback operation. the trigger thing is only used on the server side and if you call the method, you'll always get a partial postback.

i'm still not sure on what you're looking for...if you get an exception during a partial postback the only thing you need is to handle the client endRequest event (raised by the pagerequestmanager) and use some js to show the exception on that label...


Guys while were are at this User control juncture, I would need help with a silly question that I havent been able to find an answer to yet. User Control inheritance. How would you go about changing the property of something from an inherited user control or override a base control from a inherited user control.

I have all the code, if you need it to help me but I am unable to get it so far. Rest all works fine except this bit. Any help appreciated


Thread hijacker ;) Kidding. I guess what I was hoping for was a partial postback to only occur when the specified event happens. Here's an example I have posted that does not use a usercontrol.

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %
<%@. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void h(object sender, EventArgs e)
{
this.TextBox1.Text = this.ListBox1.SelectedValue;
}

protected void btn(object sender, EventArgs e)
{
this.ListBox1.DataSource = new System.Data.DataTable();
this.ListBox1.DataBind();
}

protected void Page_Load(object sender, EventArgs e)
{
this.ListBox1.Items.Add(new ListItem("TEST", "TEST"));
this.ListBox1.Items.Add(new ListItem("TEST2", "TEST2"));
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ListBox1" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="btn" />
<asp:ListBox ID="ListBox1" runat="server" OnSelectedIndexChanged="h" AutoPostBack="true" EnableViewState="true" ></asp:ListBox>
</div>
</form>
</body>
</html
What you see is that the SelectdIndexChanged causes the partial postback, while the button click causes a full postback. I guess the big problem I have in my usercontrol is that I have a button that causes a postback, but I do not want it to cause the partial postback. I run some validation AFTER the button has been clicked, and then it will send an Event to the calling page which contains the AJAX. If this event is fired, then it should initialize the partial postback; however, it is causing a partial postback for ANY postback event raised by the usercontrol. This behavior seems really out of place to me since it is not in the updatepanel. Otherwise, there's no point at all in using the EventName with any usercontrol since it will cause the partial postback regardless of what happenes inside of it.

The solution you have posted will work, but perhaps my view on how a usercontrol behaves is miscued. In order for your solution to work, I will need to take into consideration other pages that consume this control that do not use it in AJAX. I would have to let the exception bubble up to the calling page in AJAX, otherwise, I would need to catch it via server side and display it in the literal. What do you think?


As another example, I added a second button in the usercontrol "A" in your example. What I would expect, is that since it is not part of the Trigger, it should not fire a partial postback, but it does. I have tried adding it to the RegisterAsyncPostBackControl... taking it away, etc... but I can't get it to work. Perhaps my thinking is off?


hello again.

due to the way the algorythm is built on the client side, you need to call the registerpostbackcontrol for that 2nd button (just add the line below the registerasyncpostnack cotnrol method on the user control)


That did the trick. Thanks a lot. I guess since I have a button that triggers an event in a user control, it's impossible to do a full postback when the button is pressed, but a partial postback when button is pressed and the event is raised. I ended up using client side validation in the user control (and keeping the server validation) for AJAX. THanks.


hello.

well, the important thing to keep in mind is that on the client side, there really isn't any user control. what you have are several html controls! I've been away for a long time (ie, haven't really been using asp.net ajax since it was onut some moths ago), so i can't really be specific about it. However, i recall that hte pagerequestmanager object will try to make some "smart" tests until it is able to get an element responsible for the postback. if it gets anything different from null, it'll perform a partial postback. that's why your second button still kept giving you a partial postback. btw, i think i've talked about those things in my blog (though I'm not sure)...


Thanks a lot for the clarification. That definitely makes more sense to me. Thank you. I'll check out your blog next time just to make sure I'm not asking redundant questions.

ascx and ajax

HTML Source EditorWord wrap

Hi!

I am using an chat control (ascx) on my aspx sites. Any user can post a message and press the 'Absenden' button. After that the message will be send to database through code behind. The Gridview will be updated after this. Now I am trying to change the code (to ajax) so that there is 'no' postback on clicking on the 'Absenden' button. I have just watched the video on introducing ajax and sofar i am not quite sure what to do - placing a script manager ? placing an update panel? Thanks in advance for your help!!

ASCX Code

<%@dotnet.itags.org.ControlLanguage="C#"AutoEventWireup="true"CodeFile="ajaxLaberbox.ascx.cs"Inherits="Steuerelemente_laberbox" %>
<%@dotnet.itags.org.RegisterAssembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"Namespace="System.Web.UI"TagPrefix="asp" %>
<tableborder="0"width="150">
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<tdclass="ueberschrift3"align="center">Die LOW-Laberbox</td>
</tr>
<tr>
<tdheight="1"> </td>
</tr>
<tr>
<tdheight="1">
<asp:LabelID="lblNachricht"runat="server"Text="Deine Nachricht"CssClass="ueberschrift3"></asp:Label>
</td>
<tr>
<tdalign="center"height="1"><asp:TextBoxID="txtNachricht"runat="server"Height="87px"BorderColor="Transparent"ForeColor="Black"TextMode="MultiLine"MaxLength="400"Width="160px"></asp:TextBox>
</td>
</tr>
<tr>
<tdalign="center"height="1"><asp:ButtonID="btnAbsenden"runat="server"Text="Absenden"BackColor="#EDC112"BorderWidth="0px"Font-Names="Tahoma"Font-Size="8pt"OnClick="btnAbsenden_Click"/>
</td>
</tr>
<tr>
<tdnowrap>
<asp:GridViewID="gvNachrichten"runat="server"AutoGenerateColumns="False"DataSourceID="dbNachrichten"GridLines="None"Width="175px">
<Columns>
<asp:BoundFieldDataField="text"HtmlEncode="False"SortExpression="text">
<ControlStyleWidth="150px"/>
<ItemStyleWidth="150px"Wrap="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSourceID="dbNachrichten"runat="server"ConnectionString="<%$ ConnectionStrings:dbLOWConnectionString %>"
SelectCommand="SELECT top 10 '<span class="ueberschrift3">' + benutzer + ': </span><font size="-2" color="#EDC112">(' + DATENAME(d, datum) + '.' + convert(varchar(3), DATEPART(m, datum)) + '. ' + DATENAME(hh, datum) + ':' + DATENAME(mi, datum) + ')</font><span class="normal"> ' + nachricht + '</span>' AS text FROM tblNachrichten order by id desc">
</asp:SqlDataSource>
</td>
</tr>
</table>

The page that contains that control will need to have scriptmanager tag in it. The contents of your control (After the <%@. Register %>) need to be in an update panel of its own or you could place the control in an update panel inside of the Page.

Here is a link to some code to paste inside of the control that will dynamically add a scriptmanager and add all of the controls contents to an update panel.http://forums.asp.net/t/1090648.aspx?PageIndex=2


I found the problem! Unfortunatelly it was something completly different. My project was a simple ASP.Net Website. So in myweb.configmissed all necessarytags for ajax (see below)!! Thx to Joseh Humphrey - additionally i had to add the script manager in the page not in the control!

<config section>
<httpHandlers>
<system.webServer>
and so on

IT WORKS! :-)