I cannot see what is wrong here:
Javascript
function showDialogBox(dialogText, atomicId) {
if (dialogText.text == "")
{
dialogText = "¿Do you want to continue?";
}
if ($('#' + atomicId).text() != "")
{
return confirm(dialogText);
}
else
{
return true;
}
}
The Label HTML
<asp:Label ID="AtomicId" ClientIDMode="Static" runat="server" CssClass="datalabel DHidden" />
I checked atomicId param and its "AtomicId" string, but when I check $('#' + atomicId).text, it returns:
alert($('#' + atomicId).text);
What!!??. The text of the Label AtomicId is supposed to be empty the first call.
I updated it with the rest of my code where I call the function. Anyway Shobhit Walia solved it.
protected void GridDecisionsView_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Attributes.Add("style", "display:none");
e.Row.Cells[1].Attributes.Add("style", "display:none");
e.Row.Cells[2].Attributes.Add("style", "display:none");
e.Row.Cells[3].Attributes.Add("style", "display:none");
if (e.Row.RowIndex != -1)
e.Row.Attributes.Add("onclick", "if(showDialogBox('" + getDialogString() + "', '" + AtomicId.ID + "')){"
+ CSM.GetPostBackEventReference((Control)sender, "Select$" + e.Row.RowIndex.ToString()) + "}");
}
Thanks,
Try with these
function showDialogBox(dialogText, atomicId) {
if (dialogText == "")
{
dialogText = "¿Do you want to continue?";
}
if ($('#' + atomicId).text() != "")
{
return confirm(dialogText);
}
}
Related
This is the webform1 code and I made a string called pass to store the text in. What should I do in webform2 to display the message based on the conditions?
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("two.aspx", true);
if (Request.Form["TextBox1"] != null && Request.Form["TextBox2"] != null)
{
if (RadioButton2.Checked)
{
//pass = Response.ToString().Insert(Response.ToString().Count(), " " + "Welcome, " + Server.HtmlEncode(Request.QueryString["TextBox1"]) + ". <br/> The url is " + Server.HtmlEncode(Request.Url.ToString()));
pass = "Thank you Ms. " + TextBox1.Text + "Your Registration has been successfully completed" ;
}
else if (RadioButton1.Checked)
{
pass = "Thank you Mr. " + TextBox1.Text + "Your Registration has been successfully completed";
}
}
}
Based on whatever i understand, i am providing some solution:
in webform1.aspx:->place below code last line before closing the function
Application["pass_value"] = pass;
Response.Redirect("~/webform2");
Response.Redirect("two.aspx", true);->Not required
in webform2.aspx:
Label1.Text = Application["pass_value"].ToString();
in webform2.aspx.cs design page:
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
I created a gridview using Telerik asp.net/ajax controls and when I run the app locally the grid works fine but when pushed to my server I get the same error for all of my methods:
ASP.default_aspx' does not contain a definition for 'IssuesGrid_OnItemUpdated' and no extension method 'IssuesGrid_OnItemUpdated' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?)
I have tried deleting the reference in the grid and creating it again and letting VS create the method and then it'll work until I do that for all of the methods throwing the error and then it starts all over again.
Here is the aspx page:
<telerik:RadGrid ID="Issues" runat="server" CellSpacing="0" DataSourceID="GridSource" GridLines="None" Skin="Metro"
AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" OnItemDataBound="Issues_OnItemDataBound"
PageSize="30" EnableLinqExpressions="false" EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true"
AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
OnItemUpdated="Issues_OnItemUpdated" OnItemInserted="Issues_OnItemInserted" OnItemDeleted="Issues_OnItemDeleted"
OnItemCommand="Issues_OnItemCommand"
AutoGenerateColumns="False" ShowStatusBar="True" HorizontalAlign="Center" Height="900px">
And here are my methods in my cs file:
protected void Issues_OnItemUpdated(object sender, GridUpdatedEventArgs e)
{
if (e.Exception != null)
{
e.KeepInEditMode = true;
e.ExceptionHandled = true;
DisplayMessage(true, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " cannot be updated. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(false, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " updated");
}
}
protected void Issues_OnItemInserted(object source, GridInsertedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
e.KeepInInsertMode = true;
DisplayMessage(true, "Defect cannot be inserted. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(false, "Defect inserted!");
}
}
protected void Issues_OnItemDeleted(object source, GridDeletedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
DisplayMessage(true, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " cannot be deleted. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(false, "Defect " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " deleted");
}
}
protected void Issues_OnItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked
{
var editColumn = (GridEditCommandColumn)Issues.MasterTableView.GetColumn("EditCommandColumn");
editColumn.Visible = false;
}
else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted)
{
e.Canceled = true;
}
else
{
var editColumn = (GridEditCommandColumn)Issues.MasterTableView.GetColumn("EditCommandColumn");
if (!editColumn.Visible)
editColumn.Visible = true;
}
}
What's weird is I have an ondatabound method that is just fine and worked before any of these problems started and continues to work. I tried changing the 'object sender' to 'object source' but still a no go.
Here is the OnDataBound event:
protected void Issues_OnItemDataBound(object source, GridItemEventArgs e)
{
var gridDataItem = e.Item as GridDataItem;
if (gridDataItem != null)
{
var item = gridDataItem;
//Tooltips
if (!item.IsInEditMode)
{
var cell = item["Description"];
if (cell.Text.Length > 40)
{
var originaltext = cell.Text;
cell.Text = cell.Text.Remove(40) + "...";
cell.ToolTip = originaltext;
}
}
}
}
Any help on what I am doing wrong would be great!
Your code-behind (the .cs file) gets compiled into a dll when you deploy. Ensure that when you publish, these dll files are being copied over as well. This also means your published project should not have any .cs or .designer.cs files.
the code:
$(window).keypress(function (e) {
if (e.which == 13 || e.KeyCode == 13 || e.charCode == 13) { $("#<%=Send_btn.ClientID %>").trigger("click"); }
});
<asp:Button ID="Send_btn" runat="server" Text="Send" OnClick="Send_msg_Click"></asp:Button>
c#:
protected void Send_msg_Click(object sender, EventArgs e)
{
int ToClient = int.Parse(Request["frid"].ToString());
int FromClient = int.Parse(Request["uid"].ToString());
SendChatMessage(Message_txt.Text, ToClient, false);
ConversationDIv.InnerHtml = GetChat(ToClient, FromClient, Session["history"].ToString());
Message_txt.Focus();
Message_txt.Text = "";
var sc = "ScrollCoversationDiv('" + ToClient + "')";
ScriptManager.RegisterStartupScript(this, GetType(), "MyScript", sc, true);
}
when i hit enter the Send_msg_click is called twice in google chrome why ?
I have an aspx.cs page which has a method that needs to registers the Javascript file & a method. Could someone guide me as to how to register the JS file & a method in it.
aspx.cs
protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
"TaskControlJSON", "<script language='javascript'
type='text/javascript'>" + objLoginJson + "</script>"
, false);
}
Javascript file that needs to be registered to the cs file.
function GetLoginJson(strLoginJson) {
if (strLoginJson != '' && strLoginJson != undefined) {
var objLoginJson = eval('"+strLoginJson+"');
}
if (objLoginJson.LoginSuccess == "1") {
}
else if (objLoginJson.LoginSuccess == "0") {
if (objLoginJson.txtUserName != '' && objLoginJson.txtUserName != '')
{
$('#txtUserName').attr("class", objLoginJson.txtUserName);
}
if (objLoginJson.txtPassword != '' && objLoginJson.txtPassword != '')
{
$('#txtPassword').attr("class", objLoginJson.txtPassword);
}
if (objLoginJson.txtTestTokenNumber1 != ''
&& objLoginJson.txtTestTokenNumber1 != '')
{
$('#txtTestTokenNumber1').attr("class"
, objLoginJson.txtTestTokenNumber1);
}
if (objLoginJson.txtTestTokenNumber2 != ''
&& objLoginJson.txtTestTokenNumber2 != '')
{
$('#txtTestTokenNumber2').attr("class",
objLoginJson.txtTestTokenNumber2);
}
if (objLoginJson.txtTestTokenNumber3 != ''
&& objLoginJson.txtTestTokenNumber3 != '')
{
$('#txtTestTokenNumber3').attr("class",
objLoginJson.txtTestTokenNumber3);
}
if (objLoginJson.txtTestTokenNumber4 != ''
&& objLoginJson.txtTestTokenNumber4 != '')
{
$('#txtTestTokenNumber4').attr("class",
objLoginJson.txtTestTokenNumber4);
}
}
return objLoginJson;
}
This method returns a Json string, if an user provides incorrect Login credentials.
Thanks in advance.
Since you a pretty big block of javascript code, this is best kept in a separate js file.
You can use the ScriptManager.RegisterClientScriptInclude method to achieve this.
ScriptManager.RegisterClientScriptInclude(
this,
typeof(Page),
"LoginScript",
ResolveClientUrl("~/scripts/login.js"));
You have not specified how you will use your js function GetLoginJson, so I will just give a reference. Your js file could call it by something like this:
$(document).ready(function(){
$("#loginButton").click(function(){
var strLoginJson = "";//form the string as you need
GetLoginJson(strLoginJson);
});
});
Ok, I did a little tweaking around & made it to work.
protected void Page_PreRender(object sender, EventArgs e)
{
if (strLoginJson != string.Empty)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "LoginControlJSON", "<script language='javascript' type='text/javascript'>GetLoginJson(" + strLoginJson + ");</script>", false);
}
}
I have these codes for uploading csv file. Also, I have put a GridView to display its contents. Now, what I want to do is to display error lines from the GridView, for example, if there are missing words in a particular column or row, I would want to display that that particular line is empty, and that the user has to reupload with that particular line updated. The thing is, I'm really new with this, I hope someone could help me! I do not know how to retrieve the error lines and display it on the website. These are my codes :
protected void btnUpload_Click(object sender, EventArgs e)
{
string strFileNameOnServer = fileUpload.PostedFile.FileName;
string fileExt =
System.IO.Path.GetExtension(fileUpload.FileName);
if (fileUpload.PostedFile != null && fileExt == ".csv")
{
try
{
//fileUpload.PostedFile.SaveAs(ConfigurationManager.AppSettings + appDataPath + "\\" + strFileNameOnServer);
fileUpload.PostedFile.SaveAs(Server.MapPath("~/Uploaded"));
//string appPath = HttpContext.Current.Request.ApplicationPath;
// string physicalPath = HttpContext.Current.Request.MapPath("~/MajorProject");
Label1.Text = "File name: " +
fileUpload.PostedFile.FileName + "<br>" +
fileUpload.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
fileUpload.PostedFile.ContentType;
}
catch (Exception ex)
{
Label1.Text = "Error saving <b>" + strFileNameOnServer + "</b><br>. " + ex.Message;
}
BtnImport1.Visible = true;
Cancel.Visible = true;
fileUpload.Visible = false;
btnUpload.Visible = false;
}
else
{
Label1.Text = "Error - a file name must be specified/only csv files are allowed";
return;
}
var data = File.ReadAllLines(Server.MapPath("~/Uploaded"))
.Select(line => line.Split(','))
.Select(columns => new {GuestName = columns[0], Guest_ID = columns[1], IC_Number = columns[2]});
myGridView.DataSource = data;
myGridView.DataBind();
}
Do I have to add new items into my aspx file? Like a label to display the error lines? The contents of the csv file has Name, Ic Number and also House. If so, can anyone show me the codes to do this?
You could check for missing values on GridView.RowDataBound event for yours myGridview.
Example:
void myGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// Check if any of the values of mygridview row cells are empty.
if (e.Row.Cells[0].Text == "")
{
e.Row.Cells[0].Text = "ERROR: Guest name is empty!"
e.Row.Cells[0].Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "red");
}
if (e.Row.Cells[1].Text == "")
{
e.Row.Cells[1].Text = "ERROR: Guest Id is empty!"
e.Row.Cells[1].Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "red");
}
if (e.Row.Cells[2].Text == "")
{
e.Row.Cells[2].Text = "ERROR: Ic number is empty!"
e.Row.Cells[2].Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "red");
}
}
}
Don't forget to declare it inside gridview properties:
<asp:GridView ID="myGridview"
runat="server"
OnRowDataBound="myGridView_RowDataBound">
</asp:GridView>