Need help Toggle Button in AJAx in ASP.net - c#

I want the page to be updated each time the checkbox is checked or unchecked (which is using the Toggle Button from AJAX). But I am not able to do so. I tried doing the same with a button and an imagebutton, they work great( but i faced problem when I tried to update the toggle button in the "onclick" function), but I want to do this with the toggle button, I tried various means by using Page_Load() in databinding and checkchanged events but in vain. How can I correct the code>
Also I want to resize my background according to the resolution of the user. How can I do so? I surfed the net and tried to do many things with a stylesheet but in vain. Please Help.
The Codes are given below from Vidual Studio 9.
Default.aspx :
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Confidentially for 'You'</title>
<link id="Link1" rel="Stylesheet" href="StyleSheet.css" type="text/css" runat="server" />
</head>
<body background="eternal_hearts-normal.jpg" text="white">
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<p align="center" runat="server" id="p1">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />Default Line</p>
<p align="center" id="p2">
<asp:Image ID="Image1" runat="server" EnableViewState="False" />
<asp:CheckBox ID="CheckBox1" runat="server"
oncheckedchanged="Page_Load" ondatabinding="Page_Load" />
<cc1:ToggleButtonExtender ID="CheckBox1_ToggleButtonExtender" runat="server"
Enabled="True" TargetControlID="CheckBox1" ImageWidth="19"
ImageHeight="19" UncheckedImageUrl="ToggleButton_Unchecked.gif"
CheckedImageUrl="ToggleButton_Checked.gif" ondatabinding="Page_Load">
</cc1:ToggleButtonExtender>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:ImageButton ID="ImageButton1" runat="server" Height="23px"
onclick="ImageButton1_Click" Width="30px"
ImageUrl="~/ToggleButton_Unchecked.gif" />
</p>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Default.aspx.cs :
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
static int flag = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (flag == 1)
{
f();
p1.InnerHtml = "Line 1";
}
else if (flag == 2)
{
f();
p1.InnerHtml = "Line 2";
}
else if (flag == 3)
{
f();
p1.InnerHtml = "Line 3";
}
flag++;
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
Page_Load(null, EventArgs.Empty);
}
protected void Button1_Click(object sender, EventArgs e)
{
//if (flag == 0)
//{
// flag++;
// p1.InnerHtml = "Line 1";
//}
//else if (flag == 1)
//{
// flag++;
// p1.InnerHtml = "Line 2";
//}
//else if (flag == 2)
//{
// flag++;
// p1.InnerHtml = "Line 3";
//}
}
protected void f()
{
ImageButton1.ImageUrl = "ToggleButton_Unchecked.gif";
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
}
}
Stylesheet :
img#background
{
min-width: 800px;
width: 100%;
height: auto;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
div.back
{
overflow: hidden;
left: 0;
top: 0;
position: absolute;
z-index: -9999;
}
body
{
text-align: center;
left: 50pt;
right: 50pt;
font-family: 'Bookman Old Style';
position: absolute;
z-index: auto;
width : 100%;
height : 100%;
}

A little late in answer but try this -> http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ToggleButton/ToggleButton.aspx

Related

Use asp.net button onclick method instead of submitting form

I have an asp.net Button control which I want to use to insert comments in my page. When i click on button, I want it to call a method instead of submitting the form. How do i achieve this?
This is what i have tried so far -
<%# Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
//Do some stuff here
}
</script>
<head>title and other css links go here</head>
<body>
<form id="form1" runat="server" onsubmit="false">
//Some other asp.net controls go here
<asp:Button ID="Button1" runat="server" Text="Comment" OnClick="Button1_Click"/>
</form>
</body>
</html>
Is there any other way to achieve what I am doing? Suggestions are welcome.
I don't really know exactly what you are meaning.... I think you are asking for how to insert a comment into an aspx via a shout box???... Maybe?
Here is the code to insert whatever you want to type(a comment) into your form from a "method"... although it uses a lot more than just a single method.. this is the simplest way I can think of...
This is your default.aspx (notice no master page here)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>AJAX Example for comment</title>
<link href="Main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div id="page">
<div id="main">
<div id="shoutbox">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<p>Here's what everyone is saying:</p>
<p>
<asp:UpdatePanel ID="ShoutBoxPanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblShoutBox" runat="server"></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="5000">
</asp:Timer>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAddShout"
EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</p>
<p>
<asp:UpdatePanel ID="ShoutBoxPanel2" runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<p class="label">Name:</p>
<p class="entry">
<asp:TextBox ID="txtUserName" runat="server"
MaxLength="15" Width="100px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ErrorMessage="Name is required."
ControlToValidate="txtUserName" Display="Dynamic"
CssClass="error">
</asp:RequiredFieldValidator>
</p>
<p class="label">Shout:</p>
<p class="entry">
<asp:TextBox ID="txtShout" runat="server"
MaxLength="255" Width="220px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ErrorMessage="Shout is required."
ControlToValidate="txtShout" Display="Dynamic"
CssClass="error">
</asp:RequiredFieldValidator>
</p>
<asp:Button ID="btnAddShout" runat="server" Text="Add Shout"
onclick="btnAddShout_Click" />
<asp:UpdateProgress ID="UpdateProgress1" runat="server"
DynamicLayout="False">
<ProgressTemplate>
<img src="Images/spinner.gif" alt="Please Wait" />
Comment...
</ProgressTemplate>
</asp:UpdateProgress>
</ContentTemplate>
</asp:UpdatePanel>
</p>
</div>
</div>
</div>
</form>
</body>
</html>
And this is your C# Code
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ShoutItemList shoutBox;
if (Application["ShoutBox"] == null)
{
shoutBox = new ShoutItemList();
Application.Add("ShoutBox", shoutBox);
}
else
{
shoutBox = (ShoutItemList)Application["ShoutBox"];
lblShoutBox.Text = shoutBox.Display();
}
if (ScriptManager1.IsInAsyncPostBack != true)
txtUserName.Focus();
}
protected void btnAddShout_Click(object sender, EventArgs e)
{
ShoutItem shout = new ShoutItem();
shout.UserName = txtUserName.Text;
shout.Comment = txtShout.Text;
shout.Timestamp = DateTime.Now;
Application.Lock();
ShoutItemList shoutBox = (ShoutItemList)Application["ShoutBox"];
shoutBox.Add(shout);
Application.UnLock();
lblShoutBox.Text = shoutBox.Display();
txtShout.Text = "";
txtShout.Focus();
}
}
public class ShoutItem
{
public string UserName { get; set; }
public DateTime Timestamp { get; set; }
public string Comment { get; set; }
}
public class ShoutItemList
{
private List<ShoutItem> shoutList = new List<ShoutItem>();
private void Purge()
{
DateTime purgeTime = DateTime.Now;
purgeTime = purgeTime.AddMinutes(-3);
int i = 0;
while (i < shoutList.Count)
{
if (shoutList[i].Timestamp <= purgeTime) shoutList.RemoveAt(i);
else i += 1;
}
}
public void Add(ShoutItem shout)
{
Purge();
System.Threading.Thread.Sleep(2000);
shoutList.Insert(0, shout);
}
public string Display()
{
Purge();
StringBuilder shoutBoxText = new StringBuilder();
if (shoutList.Count > 0)
{
shoutBoxText.AppendLine("<dl>");
foreach (ShoutItem shout in shoutList)
{
shoutBoxText.Append("<dt>" + shout.UserName + " (");
shoutBoxText.Append(shout.Timestamp.ToShortTimeString() + ")</dt>");
shoutBoxText.AppendLine("<dd>" + shout.Comment + "</dd>");
}
shoutBoxText.AppendLine("</dl>");
}
return shoutBoxText.ToString();
}
}
This will allow you to insert whatever comment you want. You can modify this code to your own please....
Let me know if this is the answer you seek.
Use the button's OnClientClick, like this:
<asp:Button ID="Button1" runat="server" Text="Comment" OnClientClick="return javascriptFunction();" OnClick="Button1_Click"/>
then your javascript function would look like this
function javascriptFunction() {
//do something here
return false; //if you don't want the form to POST to the server, leave this as false, otherwise true will let it continue with the POST
}

Page_Load firing twice regardless of what i do

I am working on a simple asp.net login page. Yesterday, the code was working fine. Today, it isn't.
The only thing that changed between yesterday and today is that I shut down my pc and started it again today.
The problem is that Page_Load is firing twice (I checked all the answers/solutions, and none worked (image with empty src, handling the page_load manually, setting autoEventWireUp to false...)) none of these seemed to do the trick.
PLEASE can someone help me figure out why this is happening?
Here is the code for the page and its code behind:
<%# Page Title="Login" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="True" CodeBehind="Login.aspx.cs" Inherits="MatchingWebsite.Login" MaintainScrollPositionOnPostback="true" %>
<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1><%: Title %></h1>
</hgroup>
</div>
</section>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<h2 align="center">Looking for someone to spend your time with? Want to have fun with someone you like?<br />You've come to the right place!!</h2><br /><br /><br />
<img alt="Cupid" src="Images/images.jpg" align="left" />
<img alt="Couple" align="right" src="Images/matchmaking.jpg" /><br /><br />
Username:<br />
<asp:TextBox ID="UserLogIn" runat="server" Width="174px"></asp:TextBox><br /><br />
Password:<br />
<asp:TextBox ID="UserPass" runat="server" Width="175px" TextMode="Password"></asp:TextBox><br />
<asp:Label ID="LoginError" runat="server" Text="Wrong Username/Password Combination. Try again." Visible="False"></asp:Label><br /><br />
<asp:Button ID="LoginButton" runat="server" OnClick="Login_Click" Text="Login" Width="81px" />
<asp:Button ID="NotRegistered" runat="server" Text="Not Registered?" Width="150px" OnClick="Not_Registered" />
</asp:Content>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="HeadContent">
<style type="text/css">
.auto-style1
{
width: 300px;
height: 113px;
}
</style>
</asp:Content>
And here is the code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MatchingWebsite
{
public partial class Login : System.Web.UI.Page
{
Service1 proxy = new Service1();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"]!=null && !IsPostBack)
Response.Redirect("~/EnterMyInfo.aspx");
}
protected void Login_Click(object sender, EventArgs e)
{
string user = UserLogIn.Text;
string pass = UserPass.Text;
if (user == "" || pass == "")
System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=\"JavaScript\">alert(\"Username/Password cannot be blank.\")</SCRIPT>");
else
{
if (proxy.login_service(user, pass))
{
Response.Redirect("~/EnterMyInfo.aspx");
}
else
LoginError.Visible = true;
}
}
protected void Not_Registered(object sender, EventArgs e)
{
Response.Redirect("~/SignUp.aspx");
}
}
}
Likely the webpage is really loaded twice. Check your javascripts (or any AJAX components?), or use the browser's debug console to monitor the network requests being sent. Try adding empty methods on the PreInit, PostInit (etc.) events and set breakpoints too, I bet those are hit twice as well.

Chat Application using Asp.net giving Database errors

I am making a Chat Application in ASP.NET using AJAX,LINQ to SQL and some security features for authentication purpose.The Chat will be according to a specific group.I am getting an error after I attempt to login to the Chat page(default.aspx,in my project) ,
the error is :
"The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tbmsg_tbusr2". The conflict occurred in database "test", table "dbo.tbusr", column 'usrcod'.
The statement has been terminated."
Note : tbmsg is a table for storing data about messages and tbusr for storing data about users.
The Back end Code for Default.aspx is :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
chatDataContext obj = new chatDataContext();
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
Label1.Text = "Welcome:" + Session["usrnam"].ToString();
Insert_Msg("Just Login:");
GetLoggedUser();
Get_Msg();
}
}
private void Insert_Msg(String m)
{
tbmsg k = new tbmsg { msgdsc = m, msgdat = DateTime.Now, msgfrmusrcod = Convert.ToInt32(Session["usrcod"]), msgtousrcod = null, msggrpcod = Convert.ToInt32(Request.QueryString["grpcod"]) };
obj.tbmsgs.InsertOnSubmit(k);
obj.SubmitChanges();
}
private void Get_Msg()
{
var q = from p in obj.tbmsgs
where p.msggrpcod == Convert.ToInt32(Request.QueryString["grpcod"])
select p;
StringBuilder sb = new StringBuilder();
foreach (var t in q)
{
sb.Append(t.msgdsc + ":" + t.msgdat.ToString() + ":" + t.tbusr.usrnam + "<br/>");
}
ltmsg.Text = sb.ToString();
}
private void GetLoggedUser()
{
var q = (from p in obj.tblogusrs where p.logusrusrcod == Convert.ToInt32(Session["usrcod"]) select p).SingleOrDefault();
if (q == null)
{
tblogusr x = new tblogusr { logusrusrcod = Convert.ToInt32(Session["usrcod"]), logusrgrpcod = Convert.ToInt32(Request.QueryString["grpcod"]) };
obj.tblogusrs.InsertOnSubmit(x);
obj.SubmitChanges();
}
StringBuilder sb = new StringBuilder();
var q1 = from p in obj.tblogusrs where p.logusrgrpcod == Convert.ToInt32(Request.QueryString["grpcod"]) select p;
foreach (var t in q1)
{
sb.Append(t.tbusr.usrnam + "<br/>");
}
ltuser.Text = sb.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text.Length > 0)
{
Insert_Msg(TextBox1.Text);
TextBox1.Text = String.Empty;
TextBox1.Focus();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
var q = (from p in obj.tblogusrs where p.logusrusrcod == Convert.ToInt32(Session["usrcod"]) select p).SingleOrDefault();
if (q != null)
{
obj.tblogusrs.DeleteOnSubmit(q);
obj.SubmitChanges();
}
Insert_Msg("Just Logout:");
FormsAuthentication.SignOut();
Response.Redirect("login.aspx");
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Get_Msg();
GetLoggedUser();
}
}
The HTML Code:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1
{
width: 70%;
height: 25px;
}
.auto-style2
{
height: 25px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 286px; width: 849px">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
</asp:Timer>
<table border="5" style="width: 100%; margin-right: 0px">
<tr>
<td width="30%" class="auto-style2">
<asp:Literal ID="ltuser" runat="server" />
</td>
<td class="auto-style1">
<asp:Literal ID="ltmsg" runat="server" />
</td>
</tr>
</table>
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send" />
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Logout" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
Description for tbusr table:
usrcod int primary key (auto increment)
usrnam varchar(50)
usrpwd varchar(50)
Description for tbmsg table:
msgcod int primary key (auto increment)
msgdsc varchar(100)
msgdat datetime
msgfrmusrcod int (foreign key with usrcod of tbusr)
msgtousrcod int (foreign key with usrcod of tbusr)
msggrpcod int (foreign key with grpcod of tbgrp)
Note : tbgrp is another table for storing data about groups

How do I update UpdatePanel on OnUploadedComplete event of AsyncFileUploader?

I need to upload an avatar to server in 3 steps using Ajax:
Choose file to upload.
Choose crop zone using jquery.Jcrop.js.
Create avatar and save it to DB.
I have created a user control to implement it. So user clicks the upload button and there is a modalPopUpExtender shows dialog box where users have to choose the file to upload (using AjaxToolKit File async uploader), after the file is uploaded the second PopUp extender has to show the uploaded image in another dialog box to let the user choose the rectangle to crop. And the last step (button click "Create") is to crop image and show it in the parent page. I'm successful with first step. But I can't make the uploaded image to be displayed in the second dialog box.
So here is my complete ascx file and its code behind:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Avatar.ascx.cs" Inherits="KR.Trivital.Web.UI.Controls.Avatar" %>
<script type="text/javascript">
window.onload = function () { $addHandler($get('ctl00_CntAvatarBox_ImgButtAvatarImage'), 'click', showOverlay); }
function showOverlay() {
var bid = $find('mpeBehaviorID');
bid.show();
}
function uploadComplete(sender, args) {
var bid = $find('mpeBehaviorID');
bid.hide();
var bid2 = $find('ModalPopupExtender1BehaviorID');
bid2.show();
}
</script>
<asp:UpdatePanel runat="server" ID="UpdPan">
<ContentTemplate>
<asp:Image runat="server" ID="ImgAvatarImage" Visible="false" />
<asp:ImageButton runat="server" ID="ImgButtAvatarImage" Visible="false" OnClientClick="return false;" />
<asp:Panel ID="panPopupUpload" runat="server" CssClass="popUpDetails" Width="550" Style="display: none">
<h2 class="popPanelH2"><asp:Literal runat="server" ID="ltrUploadHeader" Text="Загрузка аватара" /></h2>
<div style="background-color: Gray; padding: 20px;">
<asp:Button ID="btnShowPopupUpload" runat="server" Style="display: none" />
<asp:Button ID="btnCancelPopupUpload" runat="server" Style="display: none" />
<ajaxToolkit:ModalPopupExtender ID="mdlPopupUpload" runat="server" TargetControlID="btnShowPopupUpload"
PopupControlID="panPopupUpload" CancelControlID="btnCancelPopupUpload" BackgroundCssClass="modalBackground"
BehaviorID="mpeBehaviorID" />
<ajaxToolkit:AsyncFileUpload runat="server" ID="AsncUpload1" OnUploadedComplete="AsncUpload1_UploadedComplete"
OnClientUploadComplete="uploadComplete" />
</div>
</asp:Panel>
<asp:Panel ID="panPopupCropper" runat="server" CssClass="popUpDetails" Width="550" Style="display: none">
<h2 class="popPanelH2"><asp:Literal runat="server" ID="Literal1" Text="Выбор обрезного формата" /></h2>
<div style="background-color: Gray; padding: 20px;">
<asp:Button ID="Button1" runat="server" Style="display: none" />
<asp:Button ID="Button2" runat="server" Style="display: none" />
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Button1"
PopupControlID="panPopupCropper" CancelControlID="Button2" BackgroundCssClass="modalBackground"
BehaviorID="ModalPopupExtender1BehaviorID" />
<img runat="server" id="Img1" alt="" />
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
codebehind:
using System;
using KR.Trivital.Web.Core;
using KR.Trivital.Business.Users;
using System.Web;
using System.Drawing.Drawing2D;
using System.IO;
using System.Web.UI.WebControls;
using System.Text;
using System.Web.UI;
namespace KR.Trivital.Web.UI.Controls
{
public partial class Avatar : SharedBaseControl
{
protected void Page_Load(object sender, EventArgs e)
{
this.Visible = Page.User.Identity.IsAuthenticated;
var avatar = UserAvatarBO.Get(CurrentUserId);
if (avatar != null)
{
ImgAvatarImage.ImageUrl = avatar.ImagePath;
ImgAvatarImage.Visible = true;
}
else
{
ImgButtAvatarImage.Visible = true;
}
}
protected void lnkButtUpload_Click(object sender, EventArgs e)
{
// Показать панель загрузки
mdlPopupUpload.Show();
}
private AvatarUploader InitializeAvatarUploader()
{
var uploader = new AvatarUploader();
uploader.SmoothingMode = SmoothingMode.HighQuality;
uploader.OffSetMode = PixelOffsetMode.HighQuality;
uploader.ResizingInterpolationMode = InterpolationMode.HighQualityBicubic;
uploader.ThumbMaxHeight = SiteConfig.UserAvatarsSettings.AvatarHeight;
uploader.ThumbMaxWidth = SiteConfig.UserAvatarsSettings.AvatarWidth;
uploader.IntermidiaMaxHeight = SiteConfig.UserAvatarsSettings.UploadHeight;
uploader.IntermidiaMaxWidth = SiteConfig.UserAvatarsSettings.UploadWidth;
uploader.JpgQuality = SiteConfig.UserAvatarsSettings.AvatarQuality;
uploader.UploadFolder = SiteConfig.UserAvatarsSettings.UploadFolder + "/" + this.Page.User.Identity.Name;
return uploader;
}
protected void AsncUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
var uploader = InitializeAvatarUploader();
string returnPath = "";
uploader.UploadImage(AsncUpload1.FileContent, AsncUpload1.FileName, ref returnPath);
Img1.Src = "~/" + returnPath;
}
}
}
This is a "creative solution", but it does work.
It uses the AsyncFileUpload's OnClientUploadComplete you're already using and a Control on your page that will trigger an update on your UpdatePanel (e.g. a Button; can have display:false if you like).
function uploadComplete(sender, args) {
// Your code
__doPostBack('<%= UpdatePanelUpdatingControl.UniqueID %>', '');
}

Displaying sourcecode when clicking a button

First I have to let you know that i am a newbie in this area, learning from tutorials.
With that said I'm looking for a way to load sourcecode from the codebehind file into a textbox, when clicking a button. Same goes for the aspx file.
Im making this website, where i am going to show code examples from what im doing. So if I navigate to myweb.com/tutorial1done.aspx this page would show me the final result from the tutorial done. When i click the show source button it should make 2 textboxes visible, and add the codebehind to the first box, and the aspx source to the second box.
I don't know if it is possible, but I am hoping so.
This far i have this:
ASPX:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="DateTimeOutput.aspx.cs" Inherits="WebApplication1.DateTimeOutput" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="stylesheet" href="../styles/codeformatter.css" />
</head>
<body>
<form id="form1" runat="server">
<customControls:Header runat="server" heading="Date and Time Output" />
<div>
<asp:Panel ID="Panel1" runat="server">
<asp:TextBox ID="outputText" runat="server" Height="175px" TextMode="MultiLine"
Width="400px"></asp:TextBox>
</asp:Panel>
</div>
<asp:Panel ID="Panel2" runat="server">
<asp:Button ID="runButton" runat="server" Text="Run Code"
onclick="runButton_Click" Width="95px" />
<asp:Button ID="clearButton" runat="server" Text="Clear Console"
onclick="clearButton_Click" Width="95px" />
<br />
<br />
<asp:Button ID="dt_showSource_btn" runat="server"
onclick="dt_showSource_btn_Click" Text="Show Source" />
</asp:Panel>
<asp:Label ID="dtLabel1" runat="server" Text="Code Behind:" Visible="False"></asp:Label>
<br />
<asp:TextBox ID="dtcb_output" runat="server" Height="175px"
TextMode="MultiLine" Visible="False" Width="400px"></asp:TextBox>
<br />
<br />
<asp:Label ID="dtLabel2" runat="server" Text="ASPX:" Visible="False"></asp:Label>
<br />
<asp:TextBox ID="dtaspx_output" runat="server" Height="175px"
TextMode="MultiLine" Visible="False" Width="400px"></asp:TextBox>
</form>
</body>
</html>
And the Codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class DateTimeOutput : System.Web.UI.Page
{
protected void output(String value)
{
outputText.Text += value + Environment.NewLine;
}
protected void runButton_Click(object sender, EventArgs e)
{
DateTime dt = new DateTime();
output(dt.ToString());
DateTime nowDt = DateTime.Now;
output(nowDt.ToString());
}
protected void clearButton_Click(object sender, EventArgs e)
{
outputText.Text = "";
}
protected void dt_showSource_btn_Click(object sender, EventArgs e)
{
if (dtcb_output.Visible == false)
{
dtLabel1.Visible = true;
dtcb_output.Visible = true;
}
else
{
dtLabel1.Visible = false;
dtcb_output.Visible = false;
}
if (dtaspx_output.Visible == false)
{
dtLabel2.Visible = true;
dtaspx_output.Visible = true;
}
else
{
dtLabel2.Visible = false;
dtaspx_output.Visible = false;
}
}
}
}
For now source highlighting is not needed, unless its easy to do.
Thx in advance.
If you're refering to the actual code of your code behind file, you have a problem. As the file will be compiled and then be placed as intermediate code in a dynamic link library (.dll), you don't have access to the .aspx.cs file any more. The only way to go would be to include the code behind file with the deployd project and open it with a FileStream (or whatever) to read it and display it's content.

Categories

Resources