Showing posts with label shown. Show all posts
Showing posts with label shown. Show all posts

Wednesday, March 28, 2012

PostBack Problem, Need Help.

I have a page with a drop down that drives a gridview. Now whatever is selected the drop down will drive whats shown in the gridview. The page loads fine and the default value in the drop down loads the gridview fine. Now on each row in the gridview I have an edit button to edit that row. I use a modal popup to edit that row and save it. The modal works great and updates a row. Here is where the problem happens, if I change the drop down to a different value the gridview updates, I edit the row and the modal pop is ok and saves...but without changing the drop down again if I try to edit another row I get this error...

--------
Windows Internet Explorer
--------
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@dotnet.itags.org. Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
--------
OK
--------

Now I have tried adding that attrbute to the page tag and it still does not work...it gives me a similar error than the above one. I assume it has something to do with having all these postbacks and the modal is causing one while so is the edit button and they are conflicting somehow...anyway, any direction or solution would great. Let me know if anyone needs to see some code.

Hi Horizon,

In your modal popup, do you make partial or full postback when you update the datagrid row?

If you make partial postback, there is chance the server does not know all about this partial update, especially if you modify or update portions of your page, so by the next time you try to issue partial postback the server will complain about invalid postback event arguments.

It works if you change the dropdown because the dropdown issues full postback so the server now knows about all modifications on your page.

Is it an option to issue a full postback when you update the rows in the datagrid?

If your application does not require high grades of security, you could turn off the enableEventValidation attribute globally for your application (in web.config file).

Probably some ASPX and code-behind code would be helpful here to see how exactly you do the postbacks and updates on your page...

Kind regards,

sbogus.


Thanks you lead me on the right path, I added this to the load event...

ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnSaveRankings);

What this does is cause a full post back on the page now when I click btnSaveRankings which is in my modal panel. Though know its not saving state on my drop down...it reverts it back to the value as if you just came into the site...I am going to post my aspx and aspx.cs file...

<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="PowerRankingsAjax.admin.index" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxControlToolkit" %><!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>Add/Edit Power Rankings</title> <link href="../ModalDialogs.css" rel="stylesheet" type="text/css" /></head><body> <form id="form1" runat="server"> <div> <asp:Label ID="lblError" runat="server" Text=""></asp:Label> <ajaxControlToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxControlToolkit:ToolkitScriptManager> Edit Past Issues <br /> Select Issue: <asp:DropDownList ID="ddlIssue" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlIssue_SelectedIndexChanged"></asp:DropDownList> <br /> <asp:UpdatePanel ID="uEditPanel" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView ID="EditPowerRankings" runat="server" AutoGenerateColumns="false" OnRowCreated="EditPowerRankings_OnRowCreated" > <Columns><asp:TemplateField ShowHeader="False"><ItemTemplate> <asp:Button ID="btnEdit" runat="server" Text="Edit" OnClick="btnEdit_Click" CausesValidation="false" /></ItemTemplate></asp:TemplateField><asp:BoundField DataField="pid" /><asp:BoundField DataField="teamabbr" /><asp:BoundField DataField="team" HeaderText="Team" SortExpression="team" /><asp:BoundField DataField="rank" HeaderText="Rank" SortExpression="rank" /><asp:BoundField DataField="comment" HeaderText="Comment" SortExpression="comment" /></Columns> </asp:GridView><!--cheesy button for the modal popups target control--> <asp:Button ID="btnHiddenRankings" runat="server" style="display: none" /> <ajaxControlToolkit:ModalPopupExtender ID="mpeRankings" runat="server" TargetControlID="btnHiddenRankings" PopupControlID="pnlRankings" CancelControlID="btnCancelRankings" BackgroundCssClass="modalBackground" Drag="true" > </ajaxControlToolkit:ModalPopupExtender> <asp:Panel ID="pnlRankings" runat="server" CssClass="modalBox" Style="display: none;" Width="500px"><asp:Panel ID="RankingsCaption" runat="server" CssClass="caption" Style="margin-bottom: 10px;">Edit Rankings</asp:Panel> <asp:HiddenField ID="hidRankEditIndex" runat="server" Value="-1" /><div class="divCol"></div><div class="divColLast"> <asp:Image ID="imgTeam" runat="server" />  <asp:Label ID="lblTeamName" runat="server" Text=""></asp:Label></div><div class="clearer"></div><div class="divCol">Rank:</div><div class="divColLast">   <asp:DropDownList ID="ddlEditRank" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> <asp:ListItem>5</asp:ListItem> <asp:ListItem>6</asp:ListItem> <asp:ListItem>7</asp:ListItem> <asp:ListItem>8</asp:ListItem> <asp:ListItem>9</asp:ListItem> <asp:ListItem>10</asp:ListItem> <asp:ListItem>11</asp:ListItem> <asp:ListItem>12</asp:ListItem> <asp:ListItem>13</asp:ListItem> <asp:ListItem>14</asp:ListItem> <asp:ListItem>15</asp:ListItem> <asp:ListItem>16</asp:ListItem> <asp:ListItem>17</asp:ListItem> <asp:ListItem>18</asp:ListItem> <asp:ListItem>19</asp:ListItem> <asp:ListItem>20</asp:ListItem> <asp:ListItem>21</asp:ListItem> <asp:ListItem>22</asp:ListItem> <asp:ListItem>23</asp:ListItem> <asp:ListItem>24</asp:ListItem> <asp:ListItem>25</asp:ListItem> <asp:ListItem>26</asp:ListItem> <asp:ListItem>27</asp:ListItem> <asp:ListItem>28</asp:ListItem> <asp:ListItem>29</asp:ListItem> <asp:ListItem>30</asp:ListItem> </asp:DropDownList></div><div class="clearer"></div><div class="divCol">Comments:</div><div class="divColLast"> <asp:TextBox ID="txtComment" runat="server" TextMode="MultiLine" MaxLength="500" Width="480" Height="200"></asp:TextBox></div><div class="clearer"></div><div style="white-space: nowrap; text-align: center;"> <asp:Button ID="btnSaveRankings" runat="server" Text="Save" OnClick="btnSaveRankings_Click" CausesValidation="true" /> <asp:Button ID="btnCancelRankings" runat="server" Text="Cancel" CausesValidation="false" OnClick="btnCancelRankings_Click" /></div></asp:Panel> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlIssue" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> </div> </form></body></html>

cs file...

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;namespace PowerRankingsAjax.admin{public partialclass index : System.Web.UI.Page { powerrankings oPowerrankings =new powerrankings(); DataSet ds =new DataSet();public String strWeek;public int intCountVal;protected void Page_Load(object sender, EventArgs e) { ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnSaveRankings);if (oPowerrankings.ConnectToDatabase(lblError) ==true) {if (!Page.IsPostBack) {//GetWeek GetWeek(); BuildEditList(); BuildEditGrid(strWeek); } } ds.Dispose(); }protected void GetWeek() {//Current Week strWeek = oPowerrankings.GetMaxWeek(ds, lblError); }protected void BuildEditList() { ddlIssue.DataSource = ds.Tables[oPowerrankings.GetAllWeeks(ds, lblError).ToString()]; ddlIssue.DataTextField ="week"; ddlIssue.DataValueField ="week"; ddlIssue.DataBind(); intCountVal = oPowerrankings.GetHolder(ds, lblError);if(intCountVal > 0) { ListItem li =new ListItem("Edit","edit"); ddlIssue.Items.Add(li); }else { ListItem li =new ListItem("New","new"); ddlIssue.Items.Add(li); } lblError.Text = intCountVal.ToString();//ddlIssue.SelectedValue = strWeek; }protected void BuildEditGrid(string strWeek) { EditPowerRankings.DataSource = ds.Tables[oPowerrankings.GetEditPowerRankings(strWeek, ds, lblError).ToString()]; EditPowerRankings.DataBind(); }protected void ddlIssue_SelectedIndexChanged(object sender, EventArgs e) { strWeek = ddlIssue.SelectedValue;if (oPowerrankings.isNumeric(strWeek, System.Globalization.NumberStyles.Integer)) { BuildEditGrid(strWeek); }else { } }protected void EditPowerRankings_OnRowCreated(object sender, GridViewRowEventArgs e) { e.Row.Cells[1].Visible =false; e.Row.Cells[2].Visible =false; }protected void btnSaveRankings_Click(object sender, EventArgs e) { oPowerrankings.UpdatePowerRankings(Convert.ToInt16(hidRankEditIndex.Value), Convert.ToInt16(ddlEditRank.SelectedValue), txtComment.Text, lblError); mpeRankings.Hide(); strWeek = ddlIssue.SelectedValue; BuildEditList(); BuildEditGrid(strWeek); uEditPanel.Update(); }protected void btnCancelRankings_Click(object sender, EventArgs e) { mpeRankings.Hide(); }protected void btnEdit_Click(object sender, EventArgs e) { Button btnEdit = senderas Button; GridViewRow row = (GridViewRow)btnEdit.NamingContainer; hidRankEditIndex.Value = row.Cells[1].Text; imgTeam.ImageUrl ="../images/" + row.Cells[2].Text +".gif"; lblTeamName.Text = row.Cells[3].Text; ddlEditRank.SelectedValue = row.Cells[4].Text; txtComment.Text = row.Cells[5].Text; uEditPanel.Update(); mpeRankings.Show(); } }}

Saturday, March 24, 2012

Problem in Binding Gridview through Modal popup

Hi,

I have a gridview inside a Panel which i being is shown byModalPopupExtender, and i am also using

DynamicServiceMethod -- to call a code_behind method , which inturn binds data from a data set to the gridview inside the panel.

But at the front end, i am unable to see any grid, all that i can see is just the empty pop-up(Modal). Need help on how

to bind dynamic data to modal pop.

thanks

Vishaal

It is the continuation of above problem

<ajaxToolkit:ModalPopupExtender

ID="ModalPopupExtender"runat="server"TargetControlID="imgBtnContinue"PopupControlID="pnlDiscounts"BackgroundCssClass="modalBackground"OkControlID="OkButton"OnOkScript="onOk()"CancelControlID="CancelButton"DropShadow="true"PopupDragHandleControlID="Panel3"DynamicServiceMethod="test()" (code behind method)DynamicControlID="gvDiscountDisplay" (grid inside panel) />

when i am clicking "imgBtnContinue" .. an javascript error is raised " Sys.ArgumentException: Value must not be null for Controls and Behaviors.

Parameter name:element


<ajaxToolkit:ModalPopupExtender

ID="ModalPopupExtender"

runat="server"

TargetControlID=" <Set target Id to some dummy control id>"

PopupControlID="pnlDiscounts"

BackgroundCssClass="modalBackground"

OkControlID="OkButton"

OnOkScript="onOk()"

CancelControlID="CancelButton"

DropShadow="true"

PopupDragHandleControlID="Panel3"/>

And in the actual Button click(Code-behind) invoke theModalPopupExtender.show()

-Vishaal

Wednesday, March 21, 2012

Problem in Showing Remainder in asp.net

Hi everybody

I am trying to show remainder to user who logged in the site.Whatever task he have to do is just shown in the alert box or popup window in a particular time.I used atlas timercontrol.The coding is

<form id="form1" runat="server">

<input type='text' id='myText' runat="server" visible="false" />
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem>a</asp:ListItem>
<asp:ListItem>s</asp:ListItem>
<asp:ListItem>g</asp:ListItem>
</asp:DropDownList>
<cc1:ScriptManager ID="ScriptManager1" runat="server">
</cc1:ScriptManager>

</div>
<cc2:TimerControl ID="TimerControl1" runat="server" Interval="1000" OnTick="TimerControl1_Tick">
</cc2:TimerControl>
</form>

protected void TimerControl1_Tick(object sender, EventArgs e)
{
string qry = "select * from Task_det where alertstatus='y'";
DataSet ds = new DataSet();
ds = Newway.getTable(qry);
if (ds.Tables[0].Rows.Count != 0)
{
if (DateTime.Parse(ds.Tables[0].Rows[0]["AlertDt"].ToString()) == DateTime.Parse(System.DateTime.Now.Date.ToString()))
{
if (DateTime.Parse(ds.Tables[0].Rows[0]["AlertTime"].ToString()).Hour == DateTime.Parse(System.DateTime.Now.TimeOfDay.ToString()).Hour)
{
if (DateTime.Parse(ds.Tables[0].Rows[0]["AlertTime"].ToString()).Minute == DateTime.Parse(System.DateTime.Now.TimeOfDay.ToString()).Minute)
{

TimerControl1.Enabled = true;
// Response.Write("<script language='javascript'>alert('hai');</script>");
myText.Value = "Task:" + ds.Tables[0].Rows[0]["TaskTitle"].ToString();

//Response.Write("<script language='javascript'>var myTextField = document.getElementById('myText');alert(myTextField .value);</script>");
Response.Write("<script language='javascript'>window.open('showtask.aspx?Task="+ ds.Tables[0].Rows[0]["TaskTitle"].ToString().Trim() + "','REMAINDER','height=100,width=200');</script>");

TimerControl1.Interval = 60000;

}

else
{
TimerControl1.Interval = 30000;
}
}

}
}

Here i want to hide this page from the user timercontrol will start checking after the login process.But it should be behind the screen.Only alert popupwindow (showtask.aspx) is shown in particular.Is there any alternative sollution or extend this code..Please help.

Thanks& Regards

Jhanani.R

Hi Jhanani,

What do you mean by hiding the page from the user?
I can't get your point very well.
Looking forward to your reply.

Hello,

What you can do is, use WebService.

For example, the user logs in and goes straight to mypage.aspx; once he/she is at the page, you can have a javascript function running behind the background; the function checks the webservice, which check the database to see if the user has any remainder (task), if the webservice returns true (meaning there are remainders (tasks)), then cancel the loop and use window.open to open showtasks.aspx page of yours. If there's none, then continue looping and checking every 20 seconds or so.

I would use SetTimeOut, don't use for loop or while loop, or any loop... =)


I mean to say i dont want a separate page for clock tick it will be common for all the pages am using in project.Any pages i can navigate but the clock should

tick and check the matching time and give alert.I have completed this using atlas control.But my friends are suggesting to do it with thread and log file.log file to hold the clock tick time.

Do u have any idea please tell

Jhanani


So here is your situation:

You have a page will continualy check if there is an event for the current user, if so, a remider will show. And you intend to hide this page from the user because it actually doesn't have any visual component.

I think you can use amaster page. It works as the template of all pages in your application.

Move the code above into it so that all pages will have this function.

JananiSharma:

my friends are suggesting to do it with thread and log file.log file to hold the clock tick time.

The customer will use a browser to visit your application, but you can't start a thread on the client via the customer's browser. If you application is windows based, it's a good idea, but not for a web based application.


ya i used atlas timer control in master page and call alert popup if event occurs in the particular time.But my team leader asked me to try in windows service.Is it possible


Yes, it's a feasible solution.

You can start a thread in the windows service to monitor if there is any reminder to show. But it's necessory to install the windows service on each machine.


Will you give one example.

And in timer control when it shows alert message that time the page which is running get changes in styles .For me font size is changing when the alert message appears.But for the next clock tick it again come to previous state.Please tell me solution for this.

Thanks&Regards,

Jhanani.R


Please follow this tutorial for how to create a windows service: http://msdn2.microsoft.com/en-us/library/aa984464(VS.71).aspx

Also note that now your application isn't a web/browser based application, you are doing windows programming now.

For more information about Windows service, please read this: http://msdn2.microsoft.com/en-us/library/d56de412(VS.80).aspx


Raymond,

If the poster uses a windows service to track the tasks from the database, how does the windows service communicate with the user(s) from the web app? Does the web app have to start the communcation with the windows service first?

I am asking because I don't know; and also i have a feeling that using windows service will create more works. May be the poster (forgot what the name is) should talk with the team leader again.

And installing the service on each system is not a good idea either. What if it's a public system? Plus, you need to program to when the windows service should run and when it should not. This is when you need to use ActiveX. Or is there an easier way, or am I over thinking? I just give my opinion so that the poster should not use windows service if i'm correct ...


Raymond, clear me up if i'm talking nonsense, thanks ... =)


WishStar99:

Raymond,

If the poster uses a windows service to track the tasks from the database, how does the windows service communicate with the user(s) from the web app? Does the web app have to start the communcation with the windows service first?

I am asking because I don't know; and also i have a feeling that using windows service will create more works. May be the poster (forgot what the name is) should talk with the team leader again.

And installing the service on each system is not a good idea either. What if it's a public system? Plus, you need to program to when the windows service should run and when it should not. This is when you need to use ActiveX. Or is there an easier way, or am I over thinking? I just give my opinion so that the poster should not use windows service if i'm correct ...


Raymond, clear me up if i'm talking nonsense, thanks ... =)

Hi,

Yes, as you've mentioned, those problems do exist.

To implement the reminder with Timer on the web page is a solution, but not good enough. The thing is that if I want to receive reminder, I have to keep the browser open. While windows service can keep running without any UI.

For the windows service here, it doesn't need to communicate with the web app. It's a separate application.


Sorry i forgot to say that am developing project in web application.I want to know timer control in windows service.Thats y i asked.Will you please tell y the styles are changing after the alert message

Thanks& Regards,

Jhanani.R


Sorry i forgot to say that am doing project in web application.But i wanna know the windows service .Thats y i asked.Please tell y font changes during alert message.

Thanks&Regards,

Jhanani.R


Raymond,

I know it's a seperate application. My concern is, how does the user from the web application knows that there's a new task for him or her? Does the web app page have to communicate with the windows service somehow? Here's what I understand so far:

You have a windows service timer which detects if there's any tasks for a certain user or not, if yes, then what will happen? How does the windows service notify the user from the web application?

Raymond, again, i'm not debating with you, but i want to know so i can learn from it =) thanks ....


Okay, forget it ... i'll leave you alone. LOL.

I'll check back when the problem is solved.


JananiSharma ... let us know what's the solution is ... thanks ...