Not getting Id in Mozilla Firefox - c#

C#
HtmlButton btnSave = new HtmlButton();
btnSave.ID = "btnSave" + i.ToString();
btnSave.Attributes.Add("onClick", "javascript:return SubmitSave(" + btnSave.ID + ");");
javascript
function save(e)
{
var getId=e.id;
}
I am not getting id in Mozilla firefox,bout its working fine in IE

You can pass the Client ID instead of the ID btnSave.ClientID as ClientID is the perfect choice to deal with such a situation.
btnSave.Attributes.Add("onClick", "javascript:return SubmitSave(" + btnSave.ClientID + ");");
function save(e)
{
var getId=e; // Now you have Client ID, you can use directly instead getting through e.id
}

That is because you are using the id as a variable. Some browsers add the id:s as properties in the window object so that you can access them directly, but to make it work in anything but those few browsers you should use the getElementByID method to locate the element.
btnSave.Attributes.Add("onClick", "javascript:return SubmitSave(document.getElementByID('" + btnSave.ID + "'));");

Related

Adding blocks with jquery(append()) in asp.net mvc project

I have troubles with adding blocks with a specific attributes on my asp.net mvc project using jquery.
I need to add block into the page depending on what i have in a dropdownlist(created via c#)
I had created a hidden block in my view(view the code below) wich makes "select" tag with options from my "List"
<div id="other" class="EqItem">
<p>Else: #Html.DropDownList("else", Model.ModEq("",""))</p>
<p>Serial №: #Html.TextBox("serialelse")</p>
</div>
After loading the page i use a function which removes this block from DOM and makes the copy of html code of this block into a variable(blockToAdd )
function BlockDelete()
{
blockToAdd = $("#other").html();
$("#other").remove();
}
then i use this variable to dinamically add blocks into my page(the function below)
function ShowListEtc()
{
for (c = 0; c < 15; c++)
{
if (!$("#divotherlist" + c + "").length) {
id = "divotherlist" + c + "";
clas = "EqItem";
blockToAdd = blockToAdd.trim();
$(".rightside").append('<div id="' + id + '">' + blockToAdd
+ '<p><img id ="' + id + 'D"src="/Images/delete.png"
onclick="Delete(id)"></p></div>');
$("#" + id).attr('class', clas);
$("#"+id).show();
selectid = "othersel" + c;
$("#" + id).find("select").attr('id', selectid);
$('#' + selectid + ' option').each(function () {
this.setAttribute('id', TransL(this.text) + c);
this.setAttribute('onclick', 'MakeNameParent(id)')
});
break;
}
}
}
The point is that i try to change attributes within created block(append(') but they are not applying!
When i made the code first time, it worked, but suddenly it had stopped to work, then i tried to use .prepend instead of .append, it began to work for a while but after reopening the project, it had stopped to work again!
Please tell me what i've done incorrect!
Thank you!

how to preview a html file from database to a browser using C#

I have HTML code stored in a database and would like to display (render) it onto a view.
I wanted to show it as a normal text page.
eg: **HTML:** <h3 style="font-weight: bold">Usage:</h3>
<p style="text-decoration: underline">Viewing of Form -</p>
Should be shown as: Usage:
Viewing of Form -
I have a button as view and when clicked, it should show me the page.
I am using entity frame work so i have written,
string url = ("view.aspx?id = " + page.ID + "&Text=" + page.Text);
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open( '" + url + "', null, 'height=500,width=800,status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=yes' );", true);
and i have created a new page view.aspx and tried to use System.Web.HttpUtility.HtmlDecode(Request.QueryString["Text"]) to render the file.
But i am getting a blank page.
Please help me.
Thanks,
Can you confirm that page.Text has a value when it's being rendered?
If you are certain that the value page.Text is populated correctly (I'm assuming something like "view.aspx?id=1&Text=<h3>example post<h3>") then you may want to try encoding the string for the URL before returning it to the client.
string url = ("view.aspx?id = " + page.ID + "&Text=" + System.Web.HttpUtility.UrlEncode(page.Text));
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open( '" + url + "', null, 'height=500,width=800,status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=yes' );", true);
Then make sure that you are getting encoded characters in your links on the client.

WatIn Add a new option to a Selectlist?

I need to add a new option to a selectList in one of my unit tests, and I can't figure out how to do it.
The Dropdown currently has 2 options, I want to add a third, and use it.
I tried to use JavaScript injection using http://stevenharman.net/blog/archive/2007/07/10/add-option-elements-to-a-select-list-with-javascript.aspx as a base, but that failed. I get exceptions that crash the IE browser every time, and the text "RunScript failed" gets printed into my logs even though I don't use that text in my error output.
Is this possible in Watin? Or has Open Source Failed me?
Using the code in the link you provided, with one small change I've gotten it to work.
My changes
Changed the ID to the ID of my dropdown (of course!)
Changed the $ in the element get to 'document.getElementById'. With the $ in there instead I don't see any obvious errors or anything like that; just no action taken.
The 'New Option' is added to the dropdown as the last item and it is the selected item.
string js = "";
js = js + "var theSelectList = document.getElementById('myDropDownID'); ";
js = js + " AddSelectOption(theSelectList, \"My Option\", \"123\", true);";
js = js + " function AddSelectOption(selectObj, text, value, isSelected) ";
js = js + "{";
js = js + " if (selectObj != null && selectObj.options != null)";
js = js + "{";
js = js + " selectObj.options[selectObj.options.length] = new Option(text, value, false, isSelected);";
js = js + "}}";
myIE.Document.Eval(js);
My setup
WatiN 2.0
IE8
Win7
Checked when the dropdown has 1 entry and 2 entries; both scenarios had "My Option" added without issue.

YUI AJAX and .Net MVC

I'm having a bit of an issue with a mix between YUI's AJAX and a YUI Datatable. The AJAX request fires properly and I get back the correct data formatted as:
{NoteId:'" + result.NoteId + "', CreatedOn:'" + result.CreatedOn.ToShortDateString() +
"', UpdatedOn:'" + result.UpdatedOn.ToShortDateString() + "', CreatedBy:'" + result.CreatedBy +
"', NoteContent:'" + result.NoteContent + "'}
These match the table identities properly, and I ripped this formatting from the statement that initially creates the datatable (which works properly). I don't know if I have the 'onSuccess' messed up for my AJAX call or what, and this is my first time touching YUI.
Also, if I manually execute the noteTable.addRow and hard code the data, it works.
Code for the AJAX call and Table Update:
function addNote() {
var noteText = editor.get('element').value;
var id = '<%= Model.Menu.Level1Tab %>'
var lpqId = <%= Model.LpqID %>
var sUrl = "/Lpm/Notes";
var callback = {
success: function(o) {
noteTable.addRow(o.responseText);
},
failure: function(o) {
}
}
var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, 'id=' + id + '&noteContent=' + noteText + '&noteId=' + noteId + '&lpqId=' + lpqId);
}
I'm pretty well stuck on this, so if anyone could have a look and let me know where I messed something up, I'd appreciate it. If you need more info, I have plenty, including firebug debugging info.
Thanks in advance for the help
Looks like you need to convert the o.responseText from string to object. The JSON Utility can help you do that: http://developer.yahoo.com/yui/json/.
Incidentally, DataTable's DataSource integration can help manage these issues for you. This example (http://developer.yahoo.com/yui/examples/datatable/dt_xhrjson.html) shows you how to set up a DataSource and integrate it with a DataTable. Note how you can send a request to get some data from your server and then use one of the "onDataReturn..." methods (see "Loading data at runtime" under http://developer.yahoo.com/yui/datatable/#data) in your callback.

Using javascript to open a popup window

I would like to open a popup window using javascript in my c#.net app. This is the code in the body tag in my webform
<script language=javascript>
function openWindow(strEmail)
{
window.open('CheckEmail.aspx?email=' + strEmail + , 'Check Email','left=100,top=100,toolbar=no,scrollbars=yes,width=680,height=350');
return false;
}
</script>
this is my code in the Page_Load section
this.btnCheck.Attributes.Add("onclick", "return openWindow(" + txtEmail.Text + ");");
right now I'm trying to pass the string from my textbox "txtEmail" so in my popup window i can get the request.querystring but Im a little unsure of how the syntax is.
No need of the last +
window.open('CheckEmail.aspx?email=' + strEmail,'Check Email','left=100,top=100,toolbar=no,scrollbars=yes,width=680,height=350');
and in CheckEmail.aspx page you can get the query string as
Request.QueryString["email"]
Use a ' in the CS side inside the function around the textEmail.Text
this.btnCheck.Attributes.Add("onclick", "return openWindow('" + txtEmail.Text + "');");
Why don't you get the email in the client code if the txtEmail control is visible.
function openWindow()
{
var email = document.getElementById('<%=txtEmail.ClientID%>').value;
window.open('CheckEmail.aspx?email=' + email + , 'Check Email','left=100,top=100,toolbar=no,scrollbars=yes,width=680,height=350');
return false;
}

Categories