Showing posts with label display. Show all posts
Showing posts with label display. Show all posts

Wednesday, March 28, 2012

How do i use Tabs in Ajax in asp.net application..

Hi, i have a asp.net web application which is production... and the client wants us to display the data using the userid... right now i am using a datagrid in a simple aspx page.. but since the user has asked for that request.. i want to have 5 (tabs each for a user Id) and then display the datagrid on it... how can i do this is an existing aspx page.

I have downloaded the ajax tool kit and i dont know from where to start... by data grid is simple... just displaying the data using.. a sql query and there are few links in the datagrids to navigates to other pages...

So can I use Ajax just for one page,,, and is there anything that i need to know that will hamper production when using Ajax..

any help ,ideas and code will be greatly appreciated

Regards

Karen

You can easily only use ajax on one page, and creating the tab thing should be quite simple. There is nothing that will tamper production, since ajax is essentially an extra dll that goes in the bin folder, and a couple of additions to web.config. If I was you I would just go ahead and get my feet wet. There are some excellent getting started tutorials on this site. Just click the Ajax menu at the top of the page.

Good luck!

/Klaus


Thank you Klaus i will look into it. can you pls give me some link to it..

Regards

Karen


Hi,

Thank you for your post!

It seems that you are really a newbie to AJAX and javascript,this is a good start point for your learning:ASP.NET AJAX Roadmap

And this is a good point to start with Toolkit:http://www.asp.net/ajax/ajaxcontroltoolkit/samples/

And in my opinion, <ASP.NET AJAX in action> is a decent book to learn ASP.NET AJAX.

If you have further questions ,let me know.

Best Regards,


Jin,

Thanks for the link... and yeah i am newbie to Ajax and javascript... i had worked on tabs when i was working on VB.6 and then it was so easy then and that was 3 yrs ago.

regards,

Karen

How do I set off a process and display UpdatePanel on page load

I think this should be a simple task: I have a page that does some lengthy processing and I am using an update panel to show the user that something is happening. Currently, I have to load the page and the user has to press a buttong to start processing. Now, for me, this is a pointless step.. I want the page to kick off the server processing on page load and then display a page with the UpdatePanel which is then updated when the process is complete.

What is the best way to do this?.. Any suggestions?

:)

let me try this idea. once processing starts, you had the actual update panel, and show the update progress control, which gives the idea that processing is going on another page, then show the panel back again.

just a suggestion, since Atlas allows us to work with different parts of the page, somewhat like in windows forms.

a trial.

Regards,
formationusa


repost

Hide instead of had
sorry for the mistake, i have to check my spelling more often.

let me try this idea. once processing starts, you hide the actual update panel, and show the update progress control, which gives the idea that processing is going on another page, then show the panel back again.

just a suggestion, since Atlas allows us to work with different parts of the page, somewhat like in windows forms.

a trial.

Regards,
formationusa

How do I send email using ajax modal popup extender

I have a panel that sends an email message. I wish to use an ajax modal popup extender to display this panel when a user clicks a "Contact Us" link button. I get an error message when I try to run the application. My code follows.Thank you for any suggestions.

<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID ="ContactUsLinkButton"
PopupControlID ="EmailPopupPanel"
OkControlID="OKButton"
CancelControlID="CancelButton"
DropShadow="true"
BackgroundCssClass ="modalBackground" />
<asp:LinkButton ID="ContactUsLinkButton" runat="server">Contact Us</asp:LinkButton>


<div >
<asp:Panel ID="EmailPopupPanel" runat="server" CssClass ="popupEmail" Width="325px" Style="display: none" >
<asp:Label ID="TitleLabel" runat="server" BackColor="#FFFFC0"
Font-Bold="True" Font-Size="Medium" ForeColor="SteelBlue" Text="Contact D`Stroke Tennis"
Width="300px"></asp:Label>
<br />
<asp:Label ID="InfoLabel" runat="server" Font-Bold="True" Font-Size="Medium" ForeColor="Red"></asp:Label>
<br />
<br />
<asp:Button ID="OKButton" runat="server" BackColor="#FFFFC0" Font-Bold="True" ForeColor="DarkRed"
Text="OK" Visible="False" /><br />
<span style="color: #990000"><strong><asp:Label ID="FromLabel" runat="server" Text="From:"></asp:Label></strong> </span>
<asp:TextBox ID="FromTextBox" runat="server" Width="250px" ForeColor="DarkRed"></asp:TextBox>
<br />
<br />
<asp:Label ID="ToLabel" runat="server" Text="To: admin@dotnet.itags.org.dstroketennis.com" Width="300px" BackColor="#FFFFC0" Font-Bold="True" ForeColor="DarkRed"></asp:Label>
<br />
<br />
<span style="color: #990000"><strong><asp:Label ID="SubjectLabel" runat="server"
Text="Subject:"></asp:Label></strong></span>
<asp:TextBox ID="SubjectTextBox" runat="server" Width="240px"></asp:TextBox><br />
<br />
<span style="color: #990000"><strong>
<asp:Label ID="MessageLabel" runat="server"
Text="Message:"></asp:Label></strong></span><br />
<asp:TextBox ID="MessageTextBox" runat="server" Height="150px" TextMode="MultiLine"
Width="300px" ForeColor="DarkRed"></asp:TextBox><br />
<asp:Button ID="SendEmailButton" runat="server" BackColor="#FFFFC0" BorderColor="DarkRed"
BorderStyle="Solid" Font-Bold="True" ForeColor="DarkRed" Text="Send Email" Width="173px" />
<br />
<asp:Button ID="CancelButton" runat="server" BackColor="#FFFFC0" BorderColor="DarkRed"
BorderStyle="Solid" Font-Bold="True" ForeColor="SteelBlue" Text="Cancel Email" Width="173px" /></asp:Panel>
</div>
</form>
</body>

Tags:ajax, ie 7, Microsoft JScript runtime error: Sys.ArgumentNullException: Value cannot be null. Parameter name: element

When do you get the Sys.ArgumentNullException error? Also, try getting rid of the Style="display: none" on the Panel...

-Damien


I get the error when the page loads.


I Got rid of the Style "display : none" and I get the same error on page load.


See if this related post helps:http://forums.asp.net/p/1107533/1700376.aspx

-Damien


I also ran across this:http://www.spthorn.com/blog.php?post=28&PHPSESSID=c42ace58bb0f0d24ab3d9d2eef948c4a

-Damien


Thanks Damien. The asp buttons weren't plugged into anything I am guessing. My new challenge with this now is to have the email send, and display a message that the send was a success before leaving modal state.

At least this one issue is handled.

Monday, March 26, 2012

How do I Display an Animated GIF when afile is uploaded?

I cant believe how difficult this is to do. I asusmed using an updatepanel and an updateprogress control would handle this easily. My code is below. However "FileUpload1.PostedFile.FileName" is

always set to null. Can anyone suggest how I can display a simple animated gif when Im uploading a file to the server. I dont want a progress bar just a simple animated gif to show that something is a happening. Thanks!

protected void Button3_Click(object sender, EventArgs e)
{
string File1 = FileUpload1.PostedFile.FileName;

}

ASP.NET code:

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>

<asp:Button ID="Button3" runat="server" Style="z-index: 113; left: 8px; position: absolute;
top: 108px" Text="Button" OnClick="Button3_Click" />
<asp:FileUpload ID="FileUpload1" runat="server" Style="z-index: 101; left: 74px;
position: absolute; top: 438px" />

</ContentTemplate>
</asp:UpdatePanel>

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="~/Graphics/CAFQW3B9.gif" Style="z-index: 100;
left: 76px; position: absolute; top: 488px" />

</ProgressTemplate>
</asp:UpdateProgress>

Hi,

there are several controls that don't work asynchronously by putting them in an UpdatePanel controls. FileUpload is one of them so you need to set the uploadbutton to be a postbacktrigger of the UpdatePanel so a normal synchronous postback will occur.

Grz, Kris.


Thanks Kris. Im new to this and Im not really sure what you mean by "postbacktrigger". Can you point me to a url or post a ccode snippet that can explain how to show my animated gif on file upload?


Hi,

rangers99:

Im new to this and Im not really sure what you mean by "postbacktrigger".

You can take a look at the example on this page:http://ajax.asp.net/docs/mref/T_System_Web_UI_PostBackTrigger.aspx.

Grz, Kris.

How do I display a simple message box using Ajax?

I'm doing a check to make sure that at least one out of 5 search text fields are entered. If none are entered, I want to display a message saying so. How do I do this?

The following works if I do not use Ajax:

DisplayClientError("My message to be displayed here");

privatevoid DisplayClientError(string errorDesc)

{

string script ="<script language=\"javascript\">alert('" + errorDesc +"');</script>";ClientScript.RegisterStartupScript(typeof(Page),"UserSecurity", script);

}

But this doesn't show up in Ajax version.

Thanks.

Use ScriptManager.RegisterStartupScript() instead.


Try this

privatevoid DisplayClientError(string errorDesc)

{

string script ="alert('" + errorDesc +"');";

ScriptManager.RegisterStartupScript(this,typeof(Page),"UserSecurity", script,true);

}


Oh !!!! I see what's happening now. Thanks a lot.


thx for that !!Smile

Saturday, March 24, 2012

How do I add a popup window within an AJAX UpdatePanel

Hi, I am new to AJAX and trying to figure out the following:

I am trying to display a popupwindow within an AJAX UpdatePanel, but when I used the following code with ajax no popup window appears. When I take it out of the update panel it works fine.

Any help would be much appreciated! Thanks.

PublicSub DisplayMessage(ByVal objPageAs System.Web.UI.Page,ByVal messageAsString) 'Replace end of line characters with JavaScript \n newline character. message = Replace(message, vbCrLf,"\n") message = Replace(message, vbCr,"\n") message = Replace(message, vbLf,"\n") message = Replace(message,"""","\""") 'Replace ugly database tags with (slightly) more meaningful text. message = Replace(message,"[DataDirect ADO Sybase Provider]","Sybase Error:") message = Replace(message,"Native Warning code","Error #:") Dim pageTypeAs Type = objPage.GetType() Dim displayNameAsString ="displayMessage" Dim csAs System.Web.UI.ClientScriptManager = objPage.ClientScript If (Not cs.IsStartupScriptRegistered(pageType, displayName))Then Dim displayTextAsString ="alert(""" & message &""");" cs.RegisterStartupScript(pageType, displayName, displayText,True) EndIf EndSub

#########################################################################

The above code is getting called from the below code.

IfNot IsDate(txtStartDate.Text)Then

DisplayMessage(Page,"Please enter a valid start date.")

ReturnFalse

EndIf

unfortunently, when firing server side functions from inside an updatepanel, it cannot make changes to the page, only to objects on the page that are inside the updatepanel. With this said, trying to write a startup script or any type of javascript block from a updatepanel partial postback will not work, probably for the same reason you cannot use the response.write method. You will either need to deal with the full page postback or handle the popup window in the javascript events.

-ALan


Hi,

to inject JavaScript during a partial postback, you should use the RegisterXXX methods of the ScriptManager control.


Hi Garbin,

Even I' looking for a similar kind issue. and I tried your suggestion, but not getting it properly. I'm getting an exception like

The Script tag registered for tpe 'ASP.sections_events_myPage_aspx' and key 'Key' has invalid characters outside of the script tags: alert();. Only properly formated script tags can be registered.

In the code behind I'm calling the function as

ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType(), "key", "alert();", False)

I think my parameters are not right. Can you give an example of this function or explain its parameters. I saw the doc on msdn but did't understand it perfectly.

Thanks,

Mehul Mistry


Hi,

Can you please check the following...

Dim script As String = "function test()" & _
" { " & _
" alert('test');" & _
" } "

ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "TestFunction", script, True)

I did the above stuff in the method which is called on asyncronous callback in AJAX. It gets executed but there is no alert() msg displayed...

Is this the correct way to do it?

Thanks,

Mehul Mistry


Hiorlash,

I think I figured out the solution.Its working for me. For your situation, What you can do is make a small js file or if you have one then add your window opening javasript function inside the js file. ( Make your javascript function take one string parameter to display your msg from code behind, Like you are doing above ).

Now in you aspx page, you must be having ScriptManager. add one element to the script manager... as follows,

<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Scripts>
<asp:ScriptReference Path="MyJavascriptFile.js" />
</Scripts>
</asp:ScriptManager>

and in the code behind, whichever method is called by the asyncronous call of AJAX, call your function as...

ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "OpenWindow", "fnOpenWindow('myMsg');", True)

This should do the job. Its working for me.

Any better ideas and comment are always welcome :-)


Hiorlash,

Above thing works great... Alternately if you don't want to create a js file then then add your javascript function in your aspx page only in the head section as

<script type="text/javascript">
function fnOpenWindow(myMsg) {
window.open("MyPage.aspx?msg="myMsg,"","scrollbars=yes,statusbar=no,directories=0,status=0,menubar=0,width=605,height=335,left=205,top=205");

// or you can use alert

// alert(myMsg);
}
</script>

and in the DisplayMessage function after you build your message string call the function as

ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "OpenWindow", "fnOpenWindow(' " & message & " ');", True)

This will also work.


Thanks Mehul,

That works great for me now.

Thanks again,
Orla


Hi, sory to pick up the conversation, but i've got the same problem.

Putting the Javascript on an .JS at the head of the control worked for me. The thing is that i'm using a composite control and i had the javascript inside it. By taking the code and creating an .Js i'm creating dependencies for it.

Is there any way to create the .js, but keeping it inside the composite control?

Thank you.

How do i abort Ajax TabContainer Tab Change?

I have a Ajax TabContainer that has 3 tabs and each of the tab contains a formview to display/update data. When the user modifies any data in the edit mode in the formview and tries to change tab without updating the data, i would like to display a warning message to alert the user that he/she has some unsaved data in the form and abort the tab change. I sort of have an idea how to do it but somehow it's giving me a runtime javascript object reference = null runtime error on sender.set_activeTabIndex(0); in tabChanged(). Can someone help please? Thanks.

Current Code:

<script type="text/javascript">

var isDirty = false;

var prevTabIndex = 0;

function tabChanged(sender, args)

{

if (isDirty)

{

sender.set_activeTabIndex(0);

prevTabIndex = parseInt(sender.get_activeTabIndex());

}

}

function setDirty(objID)

{

if (document.getElementById(objID).value != document.getElementById(objID).defaultValue)

{

//alert("Old Value: "+document.getElementById(objID).defaultValue+", New Value: "+document.getElementById(objID).value);

isDirty=true;

}

}

</script>

<cc1:TabContainerID="TabContainer1"runat="server"Width="818px"Height="260px"ActiveTabIndex="0"OnClientActiveTabChanged="tabChanged">

<cc1:TabPanelID="TabPanel1"runat="server"HeaderText="TabA">

<HeaderTemplate>TabA</HeaderTemplate>

<ContentTemplate>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:FormViewID="fvA"runat="server"DefaultMode="readonly"DataSourceID="dsA"OnModeChanging="changeFormViewMode">

<ItemTemplate>

FieldA :<%# Eval("FieldA") %>

</ItemTemplate>

<EditItemTemplate>

FieldA:

<asp:TextBoxID="TextBoxA"runat="server"Text='<%# Bind("FieldA") %>'onchange="setDirty(this.id)"></asp:TextBox>

</EditItemTemplate>

</asp:FormView>

</ContentTemplate>

</asp:UpdatePanel>

</ContentTemplate>

</cc1:TabPanel>

<cc1:TabPanelID="TabPanel2"runat="server"HeaderText="TabB">

<HeaderTemplate>TabB</HeaderTemplate>

<ContentTemplate>

<asp:UpdatePanelID="UpdatePanel2"runat="server">

<ContentTemplate>

<asp:FormViewID="fvB"runat="server"DefaultMode="readonly"DataSourceID="dsB"OnModeChanging="changeFormViewMode">

<ItemTemplate>

FieldB :<%# Eval("FieldB") %>

</ItemTemplate>

<EditItemTemplate>

FieldB:

<asp:TextBoxID="TextBoxB"runat="server"Text='<%# Bind("FieldB") %>'onchange="setDirty(this.id)"></asp:TextBox>

</EditItemTemplate>

</asp:FormView>

</ContentTemplate>

</asp:UpdatePanel>

</ContentTemplate>

</cc1:TabPanel>

Hi Sazabi,

After a quick glance, I found that there maybe a endless loop in your code. When you change the actived Tab, it will raise OnClientActiveTabChanged event and there's set_activeTabIndex() in your code, then it will raise OnClientActiveTabChanged once more.

You should do some modification. For example:

var flag = false;
function tabChanged(sender, args){
if(flag) {flag = false; return;}
flag = true;
sender.set_activeTabIndex(0);
prevTabIndex = sender.get_activeTabIndex();
}

Best regards,

Jonathan

Wednesday, March 21, 2012

How can I make a masked label in web forms?

I'm developing a web site using AJAX and I need to display some data in a label but the data must be displayed with a mask.

For example, if I have two textboxes and I wanna do a sum between then, the label must display the result. But, I don't know what can I do to use a masked label.

If somebody can help me I'll be very thankful.

Thanks in advanced

i dont know if i completely understand you. you say you need a lable to display a sum but you want it masked? what exactly do you mean by masked.

a masked label is a lable that replaces certain (or all) characters with something else. For example a credit card number in a masked label could look like

***** ***** **** 3182

you can use a simple string.Replace method, or regular expressions to mask the label. Textboxes even have a Password Type which will mask everything typed into them automatically

What exactly do you want to mask in your label?