How to apply google voice in asp.net? - asp.net

I try to call google voice.
Here is my code:
public partial class _Default : Page
{
const string apiString = "http://translate.google.com/translate_ttsie=UTF-8&q={0}&tl{1}";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "en";
WindowsMediaPlayer p = new WindowsMediaPlayer();
p.settings.volume = 100;
p.URL=string.Format(apiString,System.Net.WebUtility.UrlEncode(TextBox1.Text),Label1.Text);
}
It does not read the text. What to do?

Related

Passing parameter value is not getting

Iam passing a parameter in response.redirect,But the value is not getting on the target page
Login.aspx.cs
protected void Button1_Click(Object sender,
System.EventArgs e)
{
string umasterid = drow["UserMasterId"].ToString();
Response.Redirect("Default.aspx?Name=" + umasterid );
}
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
string Name = Request.QueryString["Name"];//value not getting here
}
what went wrong for me???
Try following:
Login.aspx
protected void Button1_Click(Object sender,System.EventArgs e)
{
Response.Redirect("Default.aspx?Name=umasterid");
}
Default.aspx
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Request.QueryString["Name"]);
}

ASP.Net OnLoad Stop event handling

I have some validation code in my WebForm page. When a user clicks on a button and does a postback.
Page_Load event gets processed then the Button1_Click event gets processed.
I can't figure out a way to stop the Button1_Click event from processing if the validation fails on Page_Load.
Is a trick to do this?
Thanks
4 variations shown below.
public partial class _Default : System.Web.UI.Page
{
private bool MyPageIsValid { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
bool valid = false; /* some routine here */
MyPageIsValid = valid;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.MyPageIsValid)
{
this.TextBox1.Text = DateTime.Now.ToLongTimeString();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
if (!this.MyPageIsValid) {return;}
this.TextBox1.Text = DateTime.Now.ToLongTimeString();
}
protected void Button3_Click(object sender, EventArgs e)
{
if (this.Page.IsValid)
{
this.TextBox1.Text = DateTime.Now.ToLongTimeString();
}
}
protected void Button4_Click(object sender, EventArgs e)
{
if (!this.Page.IsValid) {return;}
this.TextBox1.Text = DateTime.Now.ToLongTimeString();
}
}
I think it should be better to check validation conditions exactly in the Button1_Click method like this:
if (!this.IsValid()) { return; }
Also if you still want to check that conditions in Page_Load method just add simple 'bool isValid' flag to your page's class and then check it in Button1_Click:
if (!this.isValid) { return; }

Why does DataPager need Pre-Render event to work??

Having to use pre render is causing me problems.. It would be great if I did not need it.. The problem is I have the list in a user control and when I goto the next 'page' I databind.. but then the datapager prerenders.. which also does a batabind.. so it runs twice..
If I remove the prerender .. then clicking next 'page' does nothing..
Any idea?
protected void Page_Load(object sender, EventArgs e)
{
GetSearchResults();
}
//protected void dpMembers_PreRender(object sender, EventArgs e)
//{
// GetSearchResults();
//}
public void GetSearchResults()
{
List<Person> listPerson = new List<Person>();
string strServer = "localhost";
string strAppPath = Server.MapPath("/");
PersonBusiness pb = new PersonBusiness(new PersonRepository());
listPerson = pb.GetAllPersons(strServer, strAppPath);
lvPersons.DataSource = listPerson;
lvPersons.DataBind();
}
Modify your Page load to
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
GetSearchResults();
}
}
your prerender seems ok.

How to make this asp .net code work?

Can anyone tell me what I'm doing wrong?
//--- menuFac ---
public void UpdatePageById()
{
db.ModifyData("UPDATE tblsider SET colOverskrift=#1, colTekst=#2 WHERE colID=#3", _overskrift, _tekst, _id);
}
//--- where i'm trying to get some from db to edit and save the edited ---
menuFac objTekst = new menuFac();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
objTekst._id = int.Parse(Request.QueryString["colID"]);
DataRow value = objTekst.GetPageById();
txtOverskrift.Text = value["colOverskrift"].ToString();
txtTekst.Text = value["colTekst"].ToString();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
objTekst._id = int.Parse(Request.QueryString["colID"]);
objTekst._overskrift = txtOverskrift.Text;
objTekst._tekst = txtTekst.Text;
objTekst.UpdatePageById();
Response.Redirect("Protected.aspx");
}
Replace this call method
objTekst.UpdatePageById();
with
this.UpdatePageById();
UpdatePageById is method of your Page Class, not of your property objTekst

confusing Page_Load behavior

This is what I'm trying:
public partial class _Default : System.Web.UI.Page
{
String test = "hi ";
protected void Page_Load(object sender, EventArgs e)
{
test = test + test;
Button1.Value = test;
}
protected void Button2_Click(object sender, EventArgs e)
{
Button1.Value = "u're trolled !";
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
when the page is first loaded it shows "hi hi " as the Button1's value. But whenever I click Button2, it shows "u're trolled !" as Button1's value. My question is if the page is postback every time I click the button and the Page_Load is called, then why does it shows "u're trolled !" instead of appending "hi" ?? Isn't the Page_Load called every time the page reloads ?
Use this code to know which value come when :
String test = "hi ";
protected void Page_Load(object sender, EventArgs e)
{
test = test + test;
Button1.Value += test;
}
protected void Button2_Click(object sender, EventArgs e)
{
Button1.Value += "u're trolled !";
}
protected void Button1_Click(object sender, EventArgs e)
{
}
You need to understand the ASP.NET Page Life Cycle, as Code addict said its the sequence of events that causing the issue for you.
Following link will be very helpful for you.
http://msdn.microsoft.com/en-us/library/ms178472.aspx

Resources