|
OK, I'm fairly green with ASP.net and I keep running into the same problem and I've solved it in various ways but none to my satisfaction.
What I want:
- To be able to click on a button/link or choose an option from a dropdownlist and have a tab be updated immediately with data supplied by the event set off by the button/link/dropdown.
What I can do so far:
- First click updates the tab and *then* sets the necessary variables that my tab needs to update properly. A second click re-updates the tab correctly.
So, I use the OnClick event (or similar) of the button to set Session variables (values of which may come from a db) that the tab's OnLoad event needs to load itself properly. Unfortunately, the OnLoad of the tab happens before the OnClick of the button.
Question:
- What is the standard, non-javascript, way of making a C# function happen before the button engages the OnLoad event? Preferably I'd like the OnLoad to only happen once, but if the only way is for the thing to be set off twice, I can live with that.
Alex
|
|
|
|
|
google ASP.NET page life cycle. The on load event will ALWAYS occur before the On click event. Once you understand the cycle better it will help you rearrange your code to fit it to get the desired results
|
|
|
|
|
That's my question: How *do* I rearrange my code to fit the desired result?
Or, is there some AJAXy thing I can do to the button that will allow code to run first and then load a control?
(I should have mentioned that I have looked at the page lifecycle and I still have no idea how to accomplish what I need. My workaround so far has been requiring a selection of an item (datagrid selection, dropdown selection, etc.) and then a button click to confirm the selection.)
Alex
|
|
|
|
|
You had not indicated it was in a ajax call. Typically when an item is not updated in a ajax call even though you attempt to on the server side, the item that does not update isn't in the ajax container that is being updated and therefore doesn't change on the client but the server thinks it has still. A 2nd postback reveals the change.
edit for typo
modified on Wednesday, March 25, 2009 8:58 AM
|
|
|
|
|
Well, in this case, the problem is that I click the button and...
1. The tab, I want updated, gets updated with old information thanks to obsolete session variables and whatnot.
2. The C# code executes - changing the session variables to the values I need (the values being decided by which GridView row the user selected and/or by querying the db).
Result: A tab with old information.
What would I need to do to recover the correct values I need and then update the tab with one click/selection?
Alex
|
|
|
|
|
make sure the tab is part of the ajax update. Make the changes in the onclick event. Is the tab in a update panel that is updated by the button? If not your changes will not be visible until another postback occurs. On sucessful execution of a ajax call, only items in the panel for that update change on the client. The server side viewstate however is updated with all changes. When a 2nd post back occurs, the changes from the viewstate end up showing on the client. I don't know how to be more specific.
|
|
|
|
|
I think I'll be able to figure it out from there - thanks for all the help.
Alex
|
|
|
|
|
I have a collection of 50 textboxes. I was wounding if it is possible to run a TextChange Event on a collection of textboxes instead having to add each event handler in individually.
The code behind is VB
modified on Tuesday, March 24, 2009 12:02 PM
|
|
|
|
|
Hi,
If the text boxes are not dynamic then it is very easy to make that as :
<asp:textbox id="TextBox1" runat="server" ontextchanged="TextBox_TextChanged" autopostback="True" xmlns:asp="#unknown">
<asp:textbox id="TextBox2" runat="server" ontextchanged="TextBox_TextChanged" autopostback="True" xmlns:asp="#unknown">
so on and so forth ....
in code behind
protected void TextBox_TextChanged(object sender, EventArgs e)
{
TextBox txt = ((System.Web.UI.WebControls.TextBox)(sender));
}
you can easily get which textbox changed event is called
Regards,
Milind
|
|
|
|
|
U must have assigned ID to all of ur textboxes whether u create it dynamically or us it beforehand as a static control
so u can create a centralized event handler for all ur textboxes
for eg. if i have two textboxes with their ID as say t1 and t2 respectively then
i will use this method to act as a centralized event handler for textchange d event of both as
void TextBox_TextChanged(object sender,EventArgs e)
{
TextBox t = (TextBox)sender;
switch(t.ID)
{
case "t1": Response.Write("Text Changed in t1");
break;
case "t2": Response.Write("TextChanged in t2");
break;
}
}
|
|
|
|
|
Hi
i am in requirment that,
i have a gridview with data binded. different row has different status.
on mouse hover of the status in the grid, i want to display a some message based on status of the record,
ex: if the rec is at initial stage, on mouse hover it should show all pending status like approval,review,close......
these status should be links. should be able to click on links also.
is it possible to give me some code example......
Would be very thank ful if this is sorted out.
Regards
Naina
|
|
|
|
|
Hi,
There are two ways you can do that.
1. If you are using Ajax Updatepannel then, you can easily get info from site
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HoverMenu/HoverMenu.aspx[^]
2. if it is normal Aspx page with no ajax then, on each rowbound write code for mouse hover attribute
eg.
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand'";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
}
you can also call javascript on onmouseover attribute.
Regards,
Milind
|
|
|
|
|
Thanks for the reply, i have gone through the URL given by u. but the thing is i want to bind ditterent data for different rows. so how can i do that .
Naina
|
|
|
|
|
Hi,
In that case, you can write a javscript function on onmouseover attribute, and in "Opendiv(para)" javascript method you can pass row index and show the appropriate data in DIV control.
protected void gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "javascript:OpenDiv(" + e.Row.RowIndex + ");";
e.Row.Attributes["onmouseout"] = "javascript:CloseDiv();";
}
}
Regards,
Milind
|
|
|
|
|
I am getting this error
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for niwant_gadgil@yahoo.co.in
Following is the code which i have written :
////////////////////////////////////////////////////////////////
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (tbUsrName.Text == "")
{
Response.Write("<script language='javascript'>alert(\"UserName is Blank...\");</script>");
}
else
{
try
{
string dbString = ConfigurationManager.ConnectionStrings["AppCon"].ConnectionString;
SqlConnection sqlcon = new SqlConnection(dbString);
sqlcon.Open();
SqlCommand sc = new SqlCommand("select usr_Email from usr_details where usr_ID = '" + tbUsrName.Text.ToString() + "'", sqlcon);
SqlDataReader sqldr = sc.ExecuteReader();
if (sqldr.Read())
{
string e_mail = sqldr["usr_Email"].ToString();
MailMessage msg = new MailMessage("noreplyadmin@learners21st.com", e_mail, "Password Recovery", "ur new password is 0a1b2c3d plz change it as soon as u log in");
SmtpClient mySmtp = new SmtpClient("localhost");
mySmtp.Send(msg);
lblResult.Visible = true;
lblResult.Text = "Submit occured";
}
else
{
lblResult.Text = "No Such User Found........";
lblResult.Visible = true;
}
}
catch (Exception ex)
{
lblResult.Visible = true;
lblResult.Text = ex.Message;
}
}
}
NOTE : noreplyadmin@learners21st.com doesn't exist
NOTE : I am not using ASPNETDB
///////////////////////////////////////////////////////////
In web.config i hve included this section to post the mail
<system.net>
<mailSettings>
<smtp>
<network host="localhost" port="25" defaultCredentials="true"/>
</smtp>
</mailSettings>
</system.net>
How can i solve this plz help
|
|
|
|
|
pls put the host the local ip address like 192.168.0.54 instead of localhost and then try
|
|
|
|
|
I have developed an website for forums
i want to that users who has replied to a question are also able to delete their replies
how can I achieve that plz help!!!
|
|
|
|
|
u can make the delete button either invisible/disable on rowdatabound event.
Get the id of delete column and check for the the validation which u want to give and disable it.
Naina
|
|
|
|
|
I am not using any static button control I am using AutoGenrateDeleteButton property of Grid view
|
|
|
|
|
This property also create a link and then you can find it on run time and then set it disable and enable as per your requirement.............
Thank You
Vinod Kr.
|
|
|
|
|
I make an application form it fill data into access database and send email notification, it work good but no emails I received can you please help
//the code
Imports System.Data.OleDb
Imports System.Web.Mail
Public Class newsletter1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents btn_submit As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Protected WithEvents chk_atico As System.Web.UI.WebControls.CheckBox
Protected WithEvents chk_howard As System.Web.UI.WebControls.CheckBox
Protected WithEvents chk_fakhreldin As System.Web.UI.WebControls.CheckBox
Protected WithEvents chk_vinaigrate As System.Web.UI.WebControls.CheckBox
Protected WithEvents chk_trattoria As System.Web.UI.WebControls.CheckBox
Protected WithEvents chk_nai As System.Web.UI.WebControls.CheckBox
Protected WithEvents chk_wild As System.Web.UI.WebControls.CheckBox
Protected WithEvents chk_amigo As System.Web.UI.WebControls.CheckBox
Protected WithEvents chk_bistro As System.Web.UI.WebControls.CheckBox
Protected WithEvents chk_renchai As System.Web.UI.WebControls.CheckBox
Protected WithEvents chk_taboula As System.Web.UI.WebControls.CheckBox
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btn_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_submit.Click
Dim intid As Integer
Dim atico As Integer
Dim amigo As Integer
Dim bistro As Integer
Dim fakh As Integer
Dim howard As Integer
Dim nai As Integer
Dim chai As Integer
Dim taboula As Integer
Dim tratt As Integer
Dim vinai As Integer
Dim wild As Integer
If chk_atico.Checked = False Then
Session("atico") = "0"
End If
If chk_atico.Checked = True Then
Session("atico") = "1"
End If
If chk_amigo.Checked = False Then
Session("amigo") = "0"
End If
If chk_amigo.Checked = True Then
Session("amigo") = "1"
End If
If chk_bistro.Checked = False Then
Session("bistro") = "0"
End If
If chk_bistro.Checked = True Then
Session("bistro") = "1"
End If
If chk_fakhreldin.Checked = False Then
Session("fakhreldin") = "0"
End If
If chk_fakhreldin.Checked = True Then
Session("fakhreldin") = "1"
End If
If chk_howard.Checked = False Then
Session("howard") = "0"
End If
If chk_howard.Checked = True Then
Session("howard") = "1"
End If
If chk_nai.Checked = False Then
Session("nai") = "0"
End If
If chk_nai.Checked = True Then
Session("nai") = "1"
End If
If chk_renchai.Checked = False Then
Session("chai") = "0"
End If
If chk_renchai.Checked = True Then
Session("chai") = "1"
End If
If chk_taboula.Checked = False Then
Session("taboula") = "0"
End If
If chk_taboula.Checked = True Then
Session("taboula") = "1"
End If
If chk_vinaigrate.Checked = False Then
Session("vinai") = "0"
End If
If chk_vinaigrate.Checked = True Then
Session("vinai") = "1"
End If
If chk_wild.Checked = False Then
Session("wild") = "0"
End If
If chk_wild.Checked = True Then
Session("wild") = "1"
End If
If chk_trattoria.Checked = False Then
Session("tratt") = "0"
End If
If chk_trattoria.Checked = True Then
Session("tratt") = "1"
End If
atico = Session("atico")
amigo = Session("amigo")
bistro = Session("bistro")
fakh = Session("fakhreldin")
howard = Session("howard")
nai = Session("nai")
chai = Session("chai")
tratt = Session("taboula")
vinai = Session("vinai")
wild = Session("wild")
taboula = Session("tratt")
Dim conn As OleDbConnection
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim dt As New DataTable
conn = New OleDbConnection
cmd = New OleDbCommand
da = New OleDbDataAdapter
ds = New DataSet
conn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" & Server.MapPath("\_database\atico_db.mdb") & ";"
cmd.Connection = conn
conn.Open()
cmd.CommandText = "select max(id) from ATICO"
da.SelectCommand = cmd
da.Fill(ds, "atico")
dt = ds.Tables("atico")
If IsDBNull(dt.Rows(0).Item(0)) Then
intid = 1
Else
intid = (dt.Rows(0).Item(0)) + 1
End If
conn.Close()
conn = New OleDbConnection
cmd = New OleDbCommand
da = New OleDbDataAdapter
ds = New DataSet
conn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" & Server.MapPath("\_database\atico_db.mdb") & ";"
cmd.Connection = conn
conn.Open()
cmd.CommandText = "select * from ATICO where email=@email"
cmd.Parameters.Add("@email", Session("email_atico"))
da.SelectCommand = cmd
da.Fill(ds, "atico")
dt = ds.Tables("atico")
If dt.Rows.Count > 0 Then
Response.Redirect("thank.aspx")
conn.Close()
Exit Sub
End If
conn.Close()
conn = New OleDbConnection
cmd = New OleDbCommand
da = New OleDbDataAdapter
ds = New DataSet
conn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" & Server.MapPath("\_database\atico_db.mdb") & ";"
cmd.Connection = conn
conn.Open()
cmd.Connection = conn
cmd.CommandText = "insert into ATICO" _
& " values(@id,@name,@gender,@date,@pro,@company,@position,@tel,@mobile,@email,@address,@atico,@amigo,@bistro,@fakhreldin,@howard,@nai,@chai,@taboula,@tratt,@vinai,@wild)"
cmd.Parameters.Add("@id", intid)
cmd.Parameters.Add("@name", Session("name_atico"))
cmd.Parameters.Add("@gender", Session("gender_atico"))
cmd.Parameters.Add("@date", Session("date_atico"))
cmd.Parameters.Add("@pro", Session("pro_atico"))
cmd.Parameters.Add("@company", Session("company_atico"))
cmd.Parameters.Add("@position", Session("position_atico"))
cmd.Parameters.Add("@tel", Session("tel_atico"))
cmd.Parameters.Add("@mobile", Session("mobile_atico"))
cmd.Parameters.Add("@email", Session("email_atico"))
cmd.Parameters.Add("@address", Session("address_atico"))
cmd.Parameters.Add("@atico", atico)
cmd.Parameters.Add("@amigo", amigo)
cmd.Parameters.Add("@bistro", bistro)
cmd.Parameters.Add("@fakhreldin", fakh)
cmd.Parameters.Add("@howard", howard)
cmd.Parameters.Add("@nai", nai)
cmd.Parameters.Add("@chai", chai)
cmd.Parameters.Add("@taboula", taboula)
cmd.Parameters.Add("@tratt", tratt)
cmd.Parameters.Add("@vinai", vinai)
cmd.Parameters.Add("@wild", wild)
da.InsertCommand = cmd
da.InsertCommand.ExecuteNonQuery()
conn.Close()
Dim mymsg As New MailMessage
Dim mymail As SmtpMail
mymail.SmtpServer = "localhost"
mymsg.From = Session("email_atico")
mymsg.To = "newsletter@atico-jo.com"
mymsg.To = "ahmad.bataineh@wunderman-me.com;a_bataineh@yahoo.com"
mymsg.Subject = "ATICO Newsletter"
mymsg.BodyFormat = MailFormat.Html
mymsg.Body = "<html><body>"
mymsg.Body += "New Registration for Newsletter"
mymsg.Body += "Name :" & Session("name_atico") & "<br>"
mymsg.Body += "Gender :" & Session("gender_atico") & "<br>"
mymsg.Body += "Date of Birth :" & Session("date_atico") & "<br>"
mymsg.Body += "Profession :" & Session("pro_atico") & "<br>"
mymsg.Body += "Company Name :" & Session("company_atico") & "<br>"
mymsg.Body += "Position :" & Session("position_atico") & "<br>"
mymsg.Body += "Telephone :" & Session("tel_atico") & "<br>"
mymsg.Body += "Mobile :" & Session("mobile_atico") & "<br>"
mymsg.Body += "Email :" & Session("email_atico") & "<br>"
mymsg.Body += "Address :" & Session("address_atico") & "<br>"
mymsg.Body += "</br></br></br></br></br></br></br></br></br></br></body></html>"
mymail.SmtpServer = "localhost"
mymail.Send(mymsg)
Response.Redirect("thanks.aspx")
End Sub
End Class
|
|
|
|
|
Hi,
Please set the 2 parameters before sending SMTP MailMessage :
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25");
SmtpMail.SmtpServer = "Server name"; //please specify your mail server name
Again, check the anti virus setting for the smtp mails.
Regards,
Milind
|
|
|
|
|
Bataineh wrote: I make an application form it fill data into access database and send email notification, it work good but no emails I received can you please help
So, you need to put that part of code which is not working and you think relevant, rather than putting all those line.
Bataineh wrote: mymail.SmtpServer = "localhost"
Are you sure localhost is your SMTP server IP ? and if yes , then is it configure properly? Make sure !!
cheers,
Abhijit
CodeProject MVP
|
|
|
|
|
I try my email but it not work do you have any idea please
Dim mymsg As New MailMessage
Dim mymail As SmtpMail
mymsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25");
mymail.SmtpServer = "mail.wunderman-amman.com"
mymsg.From = Session("admin@wunderman-amman.com")
mymsg.To = "admin@wunderman-amman.com"
'mymsg.To = "ahmad.bataineh@wunderman-me.com;a_bataineh@yahoo.com"
mymsg.Subject = "ATICO Newsletter"
mymsg.BodyFormat = MailFormat.Html
mymsg.Body = "<html><body>"
mymsg.Body += "New Registration for Newsletter"
mymsg.Body += "Name :" & Session("name_atico") & "<br>"
mymsg.Body += "Gender :" & Session("gender_atico") & "<br>"
mymsg.Body += "Date of Birth :" & Session("date_atico") & "<br>"
mymsg.Body += "Profession :" & Session("pro_atico") & "<br>"
mymsg.Body += "Company Name :" & Session("company_atico") & "<br>"
mymsg.Body += "Position :" & Session("position_atico") & "<br>"
mymsg.Body += "Telephone :" & Session("tel_atico") & "<br>"
mymsg.Body += "Mobile :" & Session("mobile_atico") & "<br>"
mymsg.Body += "Email :" & Session("email_atico") & "<br>"
mymsg.Body += "Address :" & Session("address_atico") & "<br>"
mymsg.Body += "</br></br></br></br></br></br></br></br></br></br></body></html>"
mymail.SmtpServer = "mail.wunderman-amman.com"
mymail.Send(mymsg)
Response.Redirect("thanks.aspx")
|
|
|
|
|
Hi,
Just Test the mail by using following code
add following in directives
Imports System.Web.Mail
and write following code :
Dim mymsg As New MailMessage()
mymsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25")
SmtpMail.SmtpServer = "mail.wunderman-amman.com"
mymsg.From = "test@test.com" ' from email id
mymsg.[To] = "test@test.com" ' to email id
mymsg.Subject = "ATICO Newsletter"
mymsg.BodyFormat = MailFormat.Html
mymsg.Body = "test"
SmtpMail.Send(mymsg)
Regrads,
Milind
|
|
|
|
|