I've placed an UpdateProgress control on my page. But it's taking up space on the form when not displayed. Is there a way to make it so that when it's not showing it won't take up any space on the page?
Never mind. I have so many panels, tables and other controls, that it realy makes it difficult to identify any problems. The UpdateProgress wasn't the issue.Wednesday, March 28, 2012
Updating a DataList with UpdatePanel
I've been trying to update my DataList with UpdatePanel but it's not working.
What I have is a text field for a user to enter comments and a save button, along with a DataList control all in an UpdatePanel.
Data is being saved on the table when the save button is clicked but the DataList is not updated unless I refresh the browser. What am I doing wrong?
Here is my ASP code:
<asp:UpdatePanel ID="UpdatePanel3" runat="server"> <ContentTemplate> <asp:Panel ID="PanelCommentBody" runat="server" CssClass="collapsePanel" Width="451px"><br /> <asp:TextBox ID="txtComments" runat="server" Height="45px" TextMode="MultiLine" Width="412px" ValidationGroup="cmnts" ></asp:TextBox><br /> <asp:Label ID="lblComment" runat="server" Text="" Font-Size="Small"></asp:Label> <asp:RequiredFieldValidator ID="RFVComments" runat="server" ErrorMessage="Please enter comment." ValidationGroup="cmnts" ControlToValidate="txtComments" Font-Size="Small" Width="154px"></asp:RequiredFieldValidator> <asp:Button ID="bttnPostComment" runat="server" Text="Post Comment" OnClick="bttnPostComment_Click" ValidationGroup="cmnts" Width="122px" /> <asp:Button ID="bttnDiscard" runat="server" Text="Discard" OnClick="bttnDiscard_Click" CausesValidation="false" /> </asp:Panel> <cc1:CollapsiblePanelExtender ID="CollapsiblePanelExtender2" runat="server" CollapseControlID="closeComment" ExpandControlID="closeComment" TargetControlID="PanelCommentBody" Collapsed="true" SuppressPostBack="true"> </cc1:CollapsiblePanelExtender> <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" Width="307px" Font-Size="Small"> <ItemTemplate> <strong>From: <a href="../Default.aspx?urnm=<%# Eval("UserName")%>"><asp:Label ID="FromLabel" runat="server" Font-Size="Small" Text='<%# Eval("UserName")%>'></asp:Label></a></strong> | Date Posted: <asp:Label ID="DateAddedLabel" runat="server" Text='<%# Eval("DateAdded", "{0:MMM dd, yy}")%>'></asp:Label><br /> <asp:Label ID="CommentLabel" runat="server" Text='<%# Eval("Comment")%>'></asp:Label><br /> <br /> </ItemTemplate> </asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyDB%>" SelectCommand="SELECT [UserName], [Comment], [DateAdded] FROM [Comments] WHERE ([CL_Id] = @dotnet.itags.org.CL_Id) ORDER BY [DateAdded] DESC"> <SelectParameters> <asp:Parameter DefaultValue="1" Name="CL_Id" Type="String" /> </SelectParameters> </asp:SqlDataSource> </ContentTemplate> </asp:UpdatePanel>
Here is my Code Behind for the save button:
protected void bttnPostComment_Click(object sender, EventArgs e)
{
string flname = Request.QueryString["filename"];
flname = flname.Substring(0, flname.Length - 4);
if (User.Identity.IsAuthenticated)
{
MembershipUser myObject = Membership.GetUser();
string usrid = myObject.ProviderUserKey.ToString();
string usrname = User.Identity.Name;
string cmmnt1 = txtComments.Text;
string connStr = ConfigurationManager.ConnectionStrings["MyDB"].ConnectionString;
SqlConnection cnn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("INSERT INTO Comments (CL_Id, UserId, UserName, Comment) VALUES ('" + flname + "', '" + usrid + "', '" + usrname + "', '" + cmmnt1 +"')", cnn);
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
}
else
{
lblComment.Text = "You need to login to make comments";
}
}
----------
Thanks in advance,
Louis
1. Make UpdatePanel UpdateMode="Conditional"
2. after cnn.close(); write UpdatePanel3.Update()
Thanks siva sakki, I tried your suggestion but it still doesn't work.
What else can I try?
Louis
Updating a DataList with UpdatePanel
On Page_Load event, register DataList control
protected void Page_Load()
{
ScriptManager1.RegisterAsyncPostBackControl(DataList1);
DataList1.DataSource = this.SqlDataSource1;
DataList1.DataBind();
}
Thanks chetan, your suggestion might work. My problem is that I have the ScriptManger1 in the master page.
How can I reference this the way you have specified above?
Thank you,
Louis
I have tried the following to reference the the ScriptManger from content panel code behind:
ScriptManager.GetCurrent(this.Page).RegisterAsyncPostBackControl(DataList1);
is this the correct way of doing it? If it is my UpdatePanel still not updating. I have also removed this two lines:
//DataList1.DataSource = this.SqlDataSource1;
//DataList1.DataBind();
It is giving me this error:
Both DataSource and DataSourceID are defined on 'DataList1'. Remove one definition.
Do I need this two lines for it to work?
I am pulling my hair on this one.
Please help. Thanks again.
Louis
If you go back to the original code you submitted and add DataList1.DataBind() at the end of the button routine, you would probably achieve the results you want.
There is nothing to cause the DataList to rebind after the button event.
If you simply delete the UpdatePanel from the page, your code would not work either. As a rule, if doesn't work without Ajax, it won't work with it. The DataBinding event for the DataList has to run on the postback.
wrayx1 that did the trick.
Thank you soooo much!!!
Louis
Just do withDataList1.DataBind();
Let me know if this helps you
Okay, I have a similar question about updating using DataList. Will someone give me a hand on this. Here's what I have.
1<asp:ScriptManager ID="ScriptManager1" runat="server">2 </asp:ScriptManager>3<%--<asp:UpdatePanel ID="UpdatePanel1" runat="server">4 <ContentTemplate>--%>5 <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True">6 <asp:ListItem Value="True">Approved</asp:ListItem>7 <asp:ListItem Value="False" Selected="True">Not Approved</asp:ListItem>8 </asp:RadioButtonList>9 <asp:SqlDataSource ID="sqlApproval" runat="server" ConnectionString="<%$ ConnectionStrings:myConnStr%>"10 SelectCommand="SELECT [frstName], [lstName], [dvlID], [mdlName], [mdnName], [degree1], [degree2], [year1], [year2], [sp_frstName], [sp_lstName], [sp_year1], [sp_year2], [sp_mdlName], [sp_mdnName], [sp_degree1], [sp_degree2], [approval] FROM [dvlStory] WHERE ([approval] = @.approval)"11 DeleteCommand="DELETE FROM [dvlStory] WHERE [dvlID] = @.dvlID"12 InsertCommand="INSERT INTO [dvlStory] ([frstName], [lstName], [mdlName], [mdnName], [degree1], [degree2], [year1], [year2], [sp_frstName], [sp_lstName], [sp_year1], [sp_year2], [sp_mdlName], [sp_mdnName], [sp_degree1], [sp_degree2], [approval]) VALUES (@.frstName, @.lstName, @.mdlName, @.mdnName, @.degree1, @.degree2, @.year1, @.year2, @.sp_frstName, @.sp_lstName, @.sp_year1, @.sp_year2, @.sp_mdlName, @.sp_mdnName, @.sp_degree1, @.sp_degree2, @.approval)"13 UpdateCommand="UPDATE [dvlStory] SET [frstName] = @.frstName, [lstName] = @.lstName, [mdlName] = @.mdlName, [mdnName] = @.mdnName, [degree1] = @.degree1, [degree2] = @.degree2, [year1] = @.year1, [year2] = @.year2, [sp_frstName] = @.sp_frstName, [sp_lstName] = @.sp_lstName, [sp_year1] = @.sp_year1, [sp_year2] = @.sp_year2, [sp_mdlName] = @.sp_mdlName, [sp_mdnName] = @.sp_mdnName, [sp_degree1] = @.sp_degree1, [sp_degree2] = @.sp_degree2, [approval] = @.approval WHERE [dvlID] = @.dvlID">14 <SelectParameters>15 <asp:ControlParameter ControlID="RadioButtonList1" Name="approval" PropertyName="SelectedValue"16 Type="Boolean" />17 </SelectParameters>18 <DeleteParameters>19 <asp:Parameter Name="dvlID" Type="Int32" />20 </DeleteParameters>21 <UpdateParameters>22 <asp:Parameter Name="frstName" Type="String" />23 <asp:Parameter Name="lstName" Type="String" />24 <asp:Parameter Name="mdlName" Type="String" />25 <asp:Parameter Name="mdnName" Type="String" />26 <asp:Parameter Name="degree1" Type="String" />27 <asp:Parameter Name="degree2" Type="String" />28 <asp:Parameter Name="year1" Type="Int32" />29 <asp:Parameter Name="year2" Type="Int32" />30 <asp:Parameter Name="sp_frstName" Type="String" />31 <asp:Parameter Name="sp_lstName" Type="String" />32 <asp:Parameter Name="sp_year1" Type="Int32" />33 <asp:Parameter Name="sp_year2" Type="Int32" />34 <asp:Parameter Name="sp_mdlName" Type="String" />35 <asp:Parameter Name="sp_mdnName" Type="String" />36 <asp:Parameter Name="sp_degree1" Type="String" />37 <asp:Parameter Name="sp_degree2" Type="String" />38 <asp:Parameter Name="approval" Type="Boolean" />39 <asp:Parameter Name="dvlID" Type="Int32" />40 </UpdateParameters>41 <InsertParameters>42 <asp:Parameter Name="frstName" Type="String" />43 <asp:Parameter Name="lstName" Type="String" />44 <asp:Parameter Name="mdlName" Type="String" />45 <asp:Parameter Name="mdnName" Type="String" />46 <asp:Parameter Name="degree1" Type="String" />47 <asp:Parameter Name="degree2" Type="String" />48 <asp:Parameter Name="year1" Type="Int32" />49 <asp:Parameter Name="year2" Type="Int32" />50 <asp:Parameter Name="sp_frstName" Type="String" />51 <asp:Parameter Name="sp_lstName" Type="String" />52 <asp:Parameter Name="sp_year1" Type="Int32" />53 <asp:Parameter Name="sp_year2" Type="Int32" />54 <asp:Parameter Name="sp_mdlName" Type="String" />55 <asp:Parameter Name="sp_mdnName" Type="String" />56 <asp:Parameter Name="sp_degree1" Type="String" />57 <asp:Parameter Name="sp_degree2" Type="String" />58 <asp:Parameter Name="approval" Type="Boolean" />59 </InsertParameters>60 </asp:SqlDataSource>61 <br />62 <asp:DataList ID="dltApproval" runat="server" BackColor="White" BorderColor="#999999"63 BorderStyle="None" BorderWidth="1px" CellPadding="3"64 GridLines="Vertical" RepeatColumns="3" RepeatDirection="Horizontal" Width="700px" DataSourceID="sqlApproval">65 <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />66 <SelectedItemStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />67 <ItemTemplate>68 <table border="0" cellpadding="2" cellspacing="0">69 <tr>70 <td>71 <asp:Label ID="frstNameLabel" runat="server" Text='<%# loadStory()%>'></asp:Label>72 </td>73 <td>74 <asp:CheckBox ID="chbApproval" runat="server" Checked='<%# Bind("approval")%>' />75 </td>76 </tr>77 </table>78 </ItemTemplate>79 <AlternatingItemStyle BackColor="Gainsboro" />80 <ItemStyle BackColor="#EEEEEE" ForeColor="Black" />81 <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />82 </asp:DataList>83<%-- </ContentTemplate>84 </asp:UpdatePanel>--%>85 <table border="0" cellpadding="5" cellspacing="0" width="700">86 <tr>87 <td style="width: 100px; text-align: center">88 <asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" Text="Update" /></td>89 <td style="width: 100px; text-align: center">90 <asp:Button ID="btnFinish" runat="server" OnClick="btnFinish_Click" Text="Finish" /></td>91 </tr>92 <>
And here's the code behind:
1protected void Page_Load(object sender, EventArgs e)2 {34 }5protected string loadStory()6 {7//load the data in here and display to the lable control8return strInfoHolder.ToString() ;9 }10protected void btnUpdate_Click(object sender, EventArgs e)11 {12 sqlApproval.Update();13 dltApproval.DataBind();14 }15protected void btnFinish_Click(object sender, EventArgs e)16 {17 Response.Redirect("~/Admin/");18 }
The problem I have is that it's not updating. At the moment, I disabled the AJAX UpdatePanel to figure out the udpate first. All I wanted is to update the Approval checkbox to the sqlDataSource control. Noticed I used Bind instead of Eval for the checkbox control that way I was hoping that once I called the sqlApproval.Update() method, the approval checkbox will automatically update the database field. However, that is not so. Any help is appreciated.
Monday, March 26, 2012
Updating and ASP Textbox from Server Side Script using AJAX Extensions
I've searched the web extensively and cannot find an answer to a question that I believe is simple.
I have an application running AJAX extensions so that scripts are run at server side. Everything works great. The problem I have is that based on selections in the script I need to base data to ASP.NET VB code behind to intergrate with an existing application.
Quite simply I want to update a hidden textbox then use that data to pass along to another asp page. I know how to pass the data once I get it to and ASP control. Just need to get it to the ASP side of the server.
Thanks in advance for any help.
Brian
I solved my problem.
Make sure there is an Name tag on the textbox that you will be using to pass info to code behind
This will accept a value and display it.
<inputtype="text"id="textbox1" value="JavaScript JumpStart"runat=server>
If you want to use the value in the code behind file this is what you need.
<inputtype="text"id="textbox1"name="textbox1"value="JavaScript JumpStart"runat=server>
Note the addition of the name tag.
Updating Gridviews
I need to update a gridview with another gridview, but I can't figure out how to do it.
I've got the AJAX component installed and it looks easy, but I can't find the right combination to make it happen.
I want the 1st control to look like this on the page...
item1
item2
item3
then when I choose one of them, I want it to update the gridview beside it.
Right now, I'm playing with the selected properties, but don't seem to have much luck.
Can anybody help me with this? it works just fine with other controls, but not with the gridview. And I know there's just something simple I'm missing.
thx.
Hello,
I would suggest using nested update panel controls. Put the second grid in one update panel, and then put both grids in new update panel. Then just put the event on wich you want the second gridView to update to the triggers collection. Example athttp://www.asp.net/AJAX/Documentation/Live/overview/UpdatePanelOverview.aspx section "Using nested UpdatePanel controls".
Saturday, March 24, 2012
Upgrade from Beta
Hi ive got a server that is running ASP.NET 2.0 AJAX Extensions Beta 2,
ivebuilt a new app using the official release 1.0, when I place the new framework on the server will it cause any issues on my existing app as they will be runing side by side?
I believe that during the installation of the latest version, you will be prompted to remove the old version first. So you will need to upgrade your existing app first.
I'm not sure if copying the dlls directly from where you installed them on your machine and pasting them into the server's GAC would work or not, but it's worth a shot. Technically they're different versions and should be capable of being installed side-by-side, but the installer doesn't allow it.
There are migration guides availablehere. Side by side install is not supported. You need to upgrade to ASP.NET AJAX 1.0.
Upgrade to Beta 1 = New Rating control error
I installed the latest framework and toolkit.
My project was working fine with a wizard control that contained rating controls. I've taken the rating controls out of the wizard template and put them in their own update panel and still receive the error. It's a very strange behavior. If I make a new page and do everything, the rating control works fine. I'm using the latest control and did all the changes required to use the new Beta. After the install, I keep receiving this error when loading the page:
System.InvalidOperationException was unhandled by user code
Message="The TargetControlID of '_RatingExtender' is not valid. The value cannot be null or empty."
Source="Microsoft.Web.Extensions"
StackTrace:
at Microsoft.Web.UI.ExtenderControl.RegisterWithScriptManager()
at Microsoft.Web.UI.ExtenderControl.OnInit(EventArgs e)
at AjaxControlToolkit.ExtenderControlBase.OnInit(EventArgs e) in C:\Program Files\Microsoft ASP.NET\AjaxControlToolkit\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs:line 338
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.AddedControl(Control control, Int32 index)
at System.Web.UI.ControlCollection.Add(Control child)
at Microsoft.Web.UI.UpdatePanel.SingleChildControlCollection.AddSingleChild(Control child)
at Microsoft.Web.UI.UpdatePanel.AddContentTemplateContainer()
at Microsoft.Web.UI.UpdatePanel.CreateContents(Boolean recreate)
at Microsoft.Web.UI.UpdatePanel.OnInit(EventArgs e)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Thanks
Anyone ? Can you please take a look? I believe others are experiencing something similar with the mentioned TargetControlID.
Thanks
When the project breaks, it breaks at the bold:
/// <summary>
/// On Init we load target properties values and process databinding handlers.
/// </summary>
/// <param name="e"></param>
protected override void OnInit(EventArgs e)
{
if (EnableClientState)
{
CreateClientStateField();
}
// EnsureProfileScriptService(ScriptManager.GetCurrent(Page), true);
Page.PreLoad += new EventHandler(Page_PreLoad);
base.OnInit(e);
}
Please reply with acomplete, self-contained sample page that demonstrates the problem. Thank you!
In my case the problem occures when I specify the rating control in the skin file.
Skinfile:
<
ajaxToolkit:Ratingrunat="server"StarCssClass="ratingStar"WaitingStarCssClass="savedRatingStar"FilledStarCssClass="filledRatingStar"EmptyStarCssClass="emptyRatingStar"/>Good to know! Do you have a complete, self-contained sample we can play with?
Just add the following 2 lines in the Default.skin file of the Ajax Control Toolkit SampleWebSite:
<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="ajaxToolkit" %>
<ajaxToolkit:Ratingrunat="server"StarCssClass="ratingStar"WaitingStarCssClass="savedRatingStar"FilledStarCssClass="filledRatingStar"EmptyStarCssClass="emptyRatingStar"/>
Then try to open the Rating sample of the SampleWebSite.
The SampleWebSite doesn't have a Default.skin file - might there be something else going on here that's causing issues?