query string in javascript function - c#

i have written the below code now i want to check whether the below code is write
bcoz when i run the program it gives me a error help needed am i doing something wrong in below code if yes plz rectify me
i m not sure how to pass query string throrugh javascript
Page.ClientScript.RegisterClientScriptBlock
(this.GetType(), "OnClick", "<script language=javascript>window.opener.location.href='~/Home.aspx?Flag= + iFlag + &BetaFlag= + iFlagBeta + &iManuf= + iManuf';</script>"
);
thanks in advance

The problem it seems to be in string creation.
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OnClick", "<script language=javascript>window.opener.location.href='~/Home.aspx?Flag=" + iFlag + "&BetaFlag=" + iFlagBeta + "&iManuf=" + iManuf + "';</script>");

Try this:
Page.ClientScript.RegisterClientScriptBlock
(this.GetType(), "OnClick",
#"<script language=javascript>
window.opener.location.href='~/Home.aspx?Flag=" + iFlag + "&BetaFlag=" + iFlagBeta + "&iManuf=" + iManuf + "';</script>"
);

Related

c# textbox-as-filename problems

I have been trying to make a program and it saves mechanics invoices. So I have got this far;
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/thing.doc");
which saves the word doc in a folder that is specified by the registration of the bike - this works fine. but what I really want is the date to be used as a filename...I couldn't figure that out, so I made a date label and plan on using the text from it as the filename instead (I know, its a long way round...but it works). Anyways, I have tried;
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + label19.Text + ".doc");
this was an "invalid filename"
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/label19.Text.doc");
this saved it as "label19.Text.doc"
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + label19.Text, ".doc");
This threw the error "(DISP_E_TYPEMISMATCH)"
All I need to do is get label19 text to work as a filename with a .doc extension...or another way of getting the date as a filename
If you need to use current date as file name then you can use:
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + DateTime.Now.ToString("MM-dd-yyyy") + ".doc")
Generate the file name in an string variable:
string filename = "C:/BMW/Invoices/" + Regbox.Text + "/" + DateTime.Now.ToString("MM-dd-yy");
and then pass it to SaveAs2 method:
oWord.Application.ActiveDocument.SaveAs2(filename, ".doc");

Web Form Cutting Off After Special Character

I have a simple web form where a person can enter into a textbox what kind of project they want. For example, they may type in: Sales & Projection report needs to be fixed.
They then click a submit button and it gets sent off to a third party website that keeps track of our projects.
The problem is, in the example given above, everything gets cut off after the '&' symbol.
it gets sent like this:
String request = "fct=createorcopyproject&guid=" + guid + "&projectname=" + TxtProjectName.Text + "&projectdesc=" + TxtDescription.Text +
"&nexttasknumber=1&budgethours=0&budgetcost=0&estimatedstartdate=" + year + "-" + month + "-" + day + "&estimatedenddate=" + year + "-" + month + "-" + day + "&estimatedhours=0&estimatedexpenses=0&projectpriorityid=" + priorityIndex + "&projectstatusid=NULL&projecttemplate=0&contactname=" + user +
"&defaultestimatedtime=0&defaulttaskstartdate=1&defaulttaskenddate=1&defaulttaskactualdates=2&clientid=" + areaIndex + "&createdefaults=True&languagedefaults=EN&projecttemplateid=0000003&keeptemplatelink=false&copyprojectassignments=True&copyprojectdocuments=True&copyforumtopics=False&copytasks=False&adjusttaskdates=False&copytaskdocuments=False&copytaskassignments=False&markproject=False&format=ds";
Where TxtDescription.Text is where we are getting the cutoff.
Is this something on their end or am I missing something?
Use HttpUtility.UrlEncode method to encode the values you send in an URL (assuming this is an URL)

C# link write fault (html)

I write a small program in c# which is send datas to a blog platform.
post.Body = postContent + "<br><img src=\"" + linkToImage + "\" />";
This is working for me right, i got the result in my blog.:
<img src="http://*************.com/wp-content/uploads/2014/06/ss.jpg" />
But i would like put after the ss.jpg the next.: style="display:none"
If i tried make this.:
post.Body = postContent + "<br><img src=\"" + linkToImage + "\" + "style="display:none"" />";
Its not working. ( would like hide the image.)
I need, the end result like this link.:
<img src="http://************/wp-content/uploads/2014/06/ss.jpg" style="display:none"/>
Can somebody help me?
Thank you
There is no string interpolation required as style="display:none;" is being output as is - it is not dependant on any condition or variable in your code therefore this should work:
post.Body = postContent + "<br><img src=\"" + linkToImage + "\" style=\"display: none;\" />";

Alert not popping up for string ASP.Net

I'm stuck again with alertboxes!
This works like a charm:
Response.Write("<script>alert('" + "Hello"+ "');</script>");
result is a string. I need to display that. This is where my problem comes in. This doesn't popup:
Response.Write("<script>alert('" + result + "');</script>");
I am passing result across many layers. Also I have used this format in all pages. Don't want a message box. Or a modal popupwindow. I want this.
I checked online and according to the syntax, it is supposed to work! Please help!
To put any value in a Javascript string literal, you need to escape apostrophes (as they are used as the delimiter for the string) and backslashes:
Response.Write(
"<script>" +
"alert('" + result.Replace("'", "\\'").Replace("\\", "\\\\") + "');" +
"</script>"
);
Try this
Response.Write("<script type='text/javascript'>alert('"+result+"')</script>")
Try this
String message = String.format({0}{1}{2},
"<script type='text/javascript'>alert('",
result,
"')</script>");
Response.Write(message);
Response.Write("<script> alert('" + HttpUtility.HtmlEncode(result) + "'); </script>")

Replace this " " with this " " using C#

I am having an issue with this blank space " " showing up in my textbox if the table row is null. so i would like to replace this " " with this "". For example here is what i have:
StartTime.Text = row.Cells[5].Text;
so here is pseudo-code of what i am trying to achieve:
if (StartTime.Text == "" " then replace it with " ")
else show the value of StartTime.Text
I know my C# skills is so bad so please help. thanks
what about StartTime.Text = row.Cells[5].Text.Replace("&nbsp", " ")
or i haven't understood the question correctly

Categories