Showing posts with label aspx. Show all posts
Showing posts with label aspx. Show all posts

Wednesday, March 28, 2012

why Javascript doesnt work properly in updatepanel?

i wanna my gridview to change into editrow model by click any space in the row , so i wrote in the aspx page:

.....
<script type="text/javascript">
function ClickEvent(cId)
{
var id=cId;
document.getElementById("rowid").value=id;
document.getElementById("btnBindData").click();
}
</script>
.....

<asp:LinkButton ID="btnBindData" runat="server" OnClick="btnBindData_Click" Width="0px" style="width:0px; height:0px"></asp:LinkButton>
<input type="hidden" id="rowid" runat="server" /> //send clicked row index to editindex property

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="userName" HeaderText="userName" SortExpression="userName" />
<asp:BoundField DataField="userPassword" HeaderText="userPassword" SortExpression="userPassword" />
</Columns>
</asp:GridView>

In the aspx.cs file i wrote:

.......

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#dfe345'");

e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

e.Row.Attributes["style"] = "Cursor:hand";

e.Row.Attributes.Add("OnClick", "ClickEvent('" + e.Row.RowIndex + "')");

}
}

......

protected void btnBindData_Click(object sender, EventArgs e)
{
GridView1.EditIndex=Convert.Int32(this.rowid.Value);

.....

GridView1.DataBind();
}

It works well without UpdatePanel ,but when put the GridView in the UpdatePanel ,when I click the row, the GridView got disappeared.

Replace asp:LinkButton with asp:Button. If you want you can sorround your button with a hidden div (to hide from the user). Also add UseSubmitBehavior="false" to the asp:Button.

For example:

<div style="display: none; line-height: 0pt;">
<asp:Button id="btnBindData" runat="server" OnClick="btnBindData_Click" UseSubmitBehavior="false" />
</div>

why ScriptManager is not recognized by VS?

Hi,

I drag and drop AJAX ScriptManager control to the source view of default.aspx, here is the code (the third and fourth lines are for ScriptManager):

<%@dotnet.itags.org. Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
Status:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Selected="True" Value="false">Active</asp:ListItem>
<asp:ListItem Value="true">Complete</asp:ListItem>
</asp:DropDownList>

But I found ScriptManager tag is underlined with curly red line. When I mouse hover on ScriptManager tag, I see a tip

Element ScriptManager is not a known element. This can occour if there is a compilation error in the website.

But I could compile and run the site successfully. The bugging thing is that all the AJAX control, such as UpdatePanel is not recognized by VS too.

any idea?

Thx

Tao

From what I know, this is what is happening...

The cause for this error is, in your web.config look for this tag...and change the tagprefix from default asp to anything else...

<controls>
<add tagPrefix="ajax" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls
and now change the <asp:UpdatePanel> to <ajax:UpdatePanel> . All your errors should be gone.

please Let us know if this fixes...


This does solve the problem. But I don't understand why. Originally, the AJAX control defined in System.Web.Extensions is registered as tagPrefix = asp. So when I use asp:ScriptManager tag, VS should be able to locate the assembly and recognize it, theoritically. Do you know why I have to replace "asp" prefix with something else, such as ajax?

Thx

Tao


Theoretically I too expected the same. We found this fix on some blog(Thanks to him for posting it), I forget the link!. But it solved the dirty red squiggly lines and I made a note of it. May be, experts here can give hind sight of why and the details behind this...

Happy Coding :)

Why there is no *.aspx.designer.vb files in Visual studio 2005?

On my computer windows XP, I use visual studio 2005 for development. I create a atlas project for my work.

Everytime when I create a new aspx or ascx file, there is no *.aspx.designer.vb file. But on some other computers(same environment), when create a new webform, VS will gerenate 3 files:

*.aspx, *.aspx.vb., *.aspx.designer.vb

Why? any settings related to this issue?

Hi,

the *.aspx.vb will not generate if you unselect checkbox "Place code in separate file" when you create a web form.

hope can help you.


Thanks for you reply. I knew that.

But I am not taliking about *.aspx.vb, I am talking about *.aspx.designer.vb

This *.aspx.designer.vb will hold all control variables declared in page *.aspx


Hi,

The computer where you can see the aspx.designer.vb file has the addin "Visual Studio 2005 Web Application Projects" available athttp://msdn.microsoft.com/asp.net/reference/infrastructure/wap/default.aspx. Be aware that by installing the addin you do loose some feature at the moment like "profile", there is a work around available also, check the code project to get the addon.

Hope this helps you.

PS: I hope that microsoft changes there mind on the designer files, i love partial classes but i do not like loosing view of the main class.

VBS1


Thanks.

So if aspx.designer.vb is invisible on my computer under a wep application inside a solution, anyway can find out this aspx.designer.vb file for webform?

Why web robots cant request aspx pages in Ajax project ?

When Icreate aspx pages in Ajaxproject googlebot, yahoo-slurp and other crawlers can’t see these pages.

I’vecreated two test sites to show the problem:

Pagewithout Ajax:http://test.cky.pl/noajax/Default.aspx

Page with Ajax:http://test.cky.pl/ajax/Default.aspx

In browserI can see both of these pages. But when I try to saw what web robot can seewhen it requests my page (I was using this page and other tools (result wasthis same):http://www.smart-it-consulting.com/internet/google/googlebot-spoofer/index.htm

For Ajax page I was gettingerror massage:Invalid URL or serverdoes not respond, HTTP return code: 500

For normalaspx page everything is ok.

If someone couldshow me solution for this problem and could explain me why robots can’t requestAjax pages Iwould be very thankful.

Have you found a solution for this yet? I also noticed the same problem. If you point the W3C link validator at an AJAX site, it just says HTTP 500 internal server error. You get the same problem if you use an link checking package such as Xenu. If you view the page in your browser, it's fine.

This concerns me as I'm heavily involved in SEO - will Googlebot see the same and not index the site...


OK, found a workaround. Add this to Page.Init:

if (Request.Browser.Crawler ==true || Request.Browser.W3CDomVersion.ToString() !="1.0" || Request.Browser.Type.ToString().Contains("Opera")){ ScriptManager1.EnablePartialRendering =false;}else{ ScriptManager1.EnablePartialRendering =true;}

Thanks a lot, it's helps.

Saturday, March 24, 2012

Wizard Control

I am using the Wizard Control in an aspx page inside an Update Panel control. What I want to do is to navigate to this page and set which Wizard Step should be active dynamically. Something like :

if(Request["whichstep"]!=null)

Wizard1.ActiveStepIndex=int.Parse(Request["whichstep"]);

Now this works fine in that the correct Wizard step is shown when the page is loaded. But the problem is that the Wizard gets STUCK on this step. i.e. you can't use the previous/next navigation buttons to move forward or backwards.

Any help would be greatly appreciated (PS. we also tried taking the Update panel out, but the same problem exists).

HN.

can you post your code? where in your code are you checking the wizard activestepindex?

Hi boolie,

Thanks for taking the time.

The code is very simple. The page that is calling the page with the Wizard has button and its click event has Response.Redirect("WizardPage.apsx?step=3");

The page that has the Wizard on it checks on the Page_Load : if(Request["step"]!=null) Wizard1.ActiveStepIndex=Int32.Parse(Request["step"]);

As I mentioned, this works. The wizard shows the correct step. But the problem is that you can't navigate i.e. go backward or forwards using the previous/next buttons.

By the way I tried putting the code in various other events that is raised by the Wizard, they all have the same behaviour!


not sure this will fix the problem, but at least it might help eliminate some things to troubleshoot...

Are you checking for whether or not it's a postback before running the "if(Request["step"]!=null)..."?

something like this:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//code would go here...
}
}

if you haven't tried this, test it and see if you notice any difference. What might be happening is that when you click on "Next" or "Previous" it's causing the page to reload which would cause the Page_Load code to run again which would show you the same step. I could be completely wrong, but at least we'll have one troubleshooting step out of the way. Let me know what happens.



Sorry. But I should have mentioned that I do test the Postback in my last Post and it still gets Stuck. Is this some kind of Bug in the Control do you think? After all they are only panels that get their visibility changed!
I kind of thought you might be checking that already. honestly, i have no idea whether or not it's a bug, but it does seem pretty strange. i'll try some tests on my own and see if i can duplicate the problem and then maybe i can help find a solution
Many Than

Many Thanks.

Looking forward to your findings.

working with AJAX?

Hi..

I wanted to use AJAX in my existing website. I refered the Ajax dll and then in my aspx page, i wrote the code as:

<asp:ScripManager ID="ScriptManager1" runat ="server" />

<asp:UpdatePanelID="EditAssoPanel"runat="server">

<ContentTemplate><asp:ButtonID="btnDisplayDestColumn"runat="server"OnClick="btnDisplayDestColumn_Click"Style="z-index: 118; left: 466px; position: absolute; top: 302px"Text="Display Dest Column"Width="176px"/>

</ContentTemplate>

</asp:UpdatePanel>

Is this the correct way to work with AJAX? I am still get the flickering, and i know its not right.. Is there anything else that i should use? please help with working AJAX..

What kind of browser do you use? Some browsers are not yet supported ( if they're not, the page will do a post back instead of partial render). Did you get any javascript error?
I am using Internet Explorer 6, Is the code that i posted earler correct? i didnt get any error. Is there any javascript code to be included

hello note when you use tha ajax control you must"btnDisplayDestColumn_Click out side of the updatepanel and

tha action happend when you click the "btnDisplayDestColumn_Click this action must in updatepanel like loading data to gridview or other

and you must have refrence to ajax control

you must use the other controls with compatibility with ajax


Hi..

Thanks for the reply. But i am sorry, i couldnt understand. Could u please explain with the code i have given

Wednesday, March 21, 2012

writing json back to client

I am making an xmlhttp request (using the scripts provided inAjax for Web Application Developersby Kris Hadlock) to get data from an aspx page. When I create a dataset and return xml with an xmldocument it works fine. I am using the following where dsreturn is the getXML of the dataset.

Dim xdocAs XmlDocument =New XmlDocument()

xdoc.LoadXml(dsreturn)

xdoc.Save(Response.OutputStream)

The problem is that I also want to return json. I have created a biz class to parse a dataset and return a json string. I know this works because I have used it in other web services. When I do this I get nothing. I think that my problem is how to return the json string in the response.outputstream. I am not sure how to do this. Just using response.write doesnt seem to work.

Thanx

Have you considered using page methods instead of doing it all by hand? They return JSON by default.

Wrong URL for Webservice

Hello

I've a Problem with Webservice Calls and/or Scripttags (not sure)
In the default.aspx I've the following Script declaration:

<asp:ScriptManager ID="scriptManager" runat="server" ScriptMode="debug">
<services>
<asp:servicereference path="~/webservices/myWebservice.asmx" />
<services>
<asp:ScriptManager /
Some times the Service is called with this URL: http://www.mySite.com/webservices/myWebservice.asmx/webservices.myWebservice
The extra "/webservices.myWebservice" is wrong and the Page could not be found.

I'm sure the wrong URL is generated from Javascript (in one of the JS-Files from the Framework) when executing the functions in myWebservice or from the generated HTML-Code from the Default.aspx Page (something like <script language="javascript" src="http://pics.10026.com/?src=http://www.mySite.com/webservices/myWebservice.asmx/webservices.myWebservice />)

Any Ideas how to solve this error? Are there any Updates for the AJAX-Framework?

Your webservice is only like thishttp://www.mySite.com/webservices/myWebservice.asmx

there is no need for webservices.myWebservice /

try it


This is the normal way a webservice method is called. There is nothing wrong in it.

The method name is appended to the webservice url

For example, if you are calling a method called method1 on webservice.asmx, the url will look like

http://.../webservice.asmx/method1


But why do I get errors like the following:

Ausnahmeinformationen:
Ausnahmetyp: InvalidOperationException
Ausnahmemeldung:Request format is unrecognized for URL unexpectedly ending in '/webservices.myWebservice'.

Anforderungsinformationen:
Anforderungs-URL:http://www.mySite.ch/webservices/myWebservice.asmx/webservices.myWebservice
Anforderungspfad: /webservices/myWebservice.asmx/webservices.myWebservice

Threadinformationen:
Thread-ID: 1
Stapelüberwachung: bei System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
bei System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
bei System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
bei System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
bei System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
bei System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

If I try to call the webservice directly, I get the same error in Browser.


Check if you have this in the web.config. I have seen this to cause this error

<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>


Thank you for the tipp. That code is not in the web.conf. I'll try if it helps.


I would guess that your web.config is missing these entries:

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpHandlers>

XHTML 1.1 Firefox and Opera problem

I installed AJAX Beta2 and used the CTP template to create a new web site. Which creates default.aspx page, with the doc type of:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
I have a table with images. I run the page in IE7 looks perfect. I ran in FF and Opera the cells height are 5 to 10 px to big. After pulling my hair for about 2 hours. I notice the doctype.
I set it to this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
And the table is correct (works in IE as well).
Should an AJAX site doctype be XHTML 1.1? Does it matter? Why did this break firefox on something so simple as a table?
Thanks
Rick 
AJAX should support site doctype XHTML 1.1 in the release version. I aslo find the similar issue to yours.The Ajax control size?is?somewhat?different?
in?different?browers?such?as?IE,FireFox,Opera,Safari.

Ajax, shorthand for Asynchronous JavaScript and XML, is a web development technique for creating interactive web applications. The intent is to make web pages feel more responsive by exchanging small amounts of data with the server behind the scenes, so that the entire web page does not have to be reloaded each time the user makes a change. This is meant to increase the web page's interactivity, speed, and usability.
The Ajax technique uses a combination of:
XHTML (or HTML) and CSS, for marking up and styling information.
The DOM accessed with a client-side scripting language, especially ECMAScript implementations such as JavaScript and JScript, to dynamically display and interact with the information presented.
The XMLHttpRequest object is used to exchange data asynchronously with the web server. In some Ajax frameworks and in certain situations, an IFrame object is used instead of the XMLHttpRequest object to exchange data with the web server, and in other implementations, dynamically added <script> tags may be used.
XML is sometimes used as the format for transferring data between the server and client, although any format will work, including preformatted HTML, plain text, JSON and even EBML. These files may be created dynamically by some form of server-side scripting.

xmlHttp with responseXML

I'm trying to write a script page that uses the xmlHTTP to an aspx page that then sends back some XML which I can then use the javascript to read and populate a dropdown list.

I seem to be running into the problem of the returned XML (or lack there of) If I do a responseText, all is well cept the response is not formatted as XML just a large string.

Here is the Javascript

1<script type="text/javascript">2 /* Create a new XMLHttpRequest object to talk to the Web server */3 var xmlHttp = false;45 function CreateXmlHttp()6 {7 /*@dotnet.itags.org.cc_on @dotnet.itags.org.*/8 /*@dotnet.itags.org.if (@dotnet.itags.org._jscript_version >= 5)910 try11 {12 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");13 } catch (e)14 {15 try16 {17 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");18 }19 catch (e2)20 {21 xmlHttp = false;22 }23 }24 @dotnet.itags.org.end @dotnet.itags.org.*/2526 if (!xmlHttp && typeof XMLHttpRequest != 'undefined')27 {28 xmlHttp = new XMLHttpRequest();29 }30 }313233 function callServ()34 {3536 var site;37 var siteddl = document.getElementById('ddlSites');38 for (var i = 0; i < siteddl.options.length; i++)39 {40 if (siteddl.options[i].selected)41 {42 site = siteddl.options[i].value;43 //document.write(site);44 }45 }46 if (site == '-1')47 {48 return;49 }50 else51 {5253 CreateXmlHttp();5455 var url="popddls.aspx?w=1&id=" + escape(site);565758 xmlHttp.open("GET", url, true);5960 xmlHttp.setRequestHeader("Content-Type", "text/xml");6162 xmlHttp.onreadystatechange = updatePage;6364 xmlHttp.send(null);65 }6667 }6869 function updatePage()70 {71 if(xmlHttp.readyState ==4)72 {73 var response1 = xmlHttp.responseXML;7475 var ddlGrades = document.getElementById('ddlGrades');7677 var grades = response1.getElementsByTagName("grade");78 //ddlGrades.options.length = 0;79 for (var x=0; x < grades.length; x++)80 {81 var id = grades[x].childNodes[0].value;82 var gradedate = grades[x].childNodes[1].value;83 document.write(id + " " + gradedate);84 var newOption = new option();85 newOption.text = gradedate;86 newOption.valueOf = id;87 ddlGrades.options[ddlGrades.length] = newOption;88 }8990 }91 }929394 </script>

Here is the code for popddl which if I run it, it does write the correct XML

1Sub load_gradesddl()2Dim idAs Integer = Request.QueryString("id")3Dim sqlAs String ="select id,gradedate from grades where siteid=" & id4Dim dsAs System.Data.DataSet = DataFunc.FillDS(sql,"gcioq")56 Response.Write("<?xml version=""1.0"" encoding=""utf-8"" ?>")7 Response.Write("<grades>")8For IAs Integer = 0To ds.Tables(0).Rows.Count - 1910 Response.Write("<grade>")11 Response.Write("<id>" & ds.Tables(0).Rows(I).Item("id") &"</id>")12 Response.Write("<gradedate>" & ds.Tables(0).Rows(I).Item("gradedate") &"</gradedate>")13 Response.Write("</grade>")14Next15 Response.Write("</grades>")16End Sub

the error I get in firefox is response1 has no properties. in IE7 I do not get an error but it doesn't work.

What am I doing wrong here?

EDIT:

I also noticed if I do a document.write(grades.length) I get a Zero back though I know the popddl is generating correct XML.

Ok, I got it to work but only in IE7, in firefox it get the right amound of nodes but everything comes out as undefined.

using this to get the data

var id = grades[x].childNodes[0].firstChild.text;

var gradedate = grades[x].childNodes[1].firstChild.text;

Also, this is the XML output

<?xml version="1.0" encoding="utf-8"?>

-<grades>

-<grade>

<id>11</id>

<gradedate>11/27/2007</gradedate>

</grade>

- <grade>

<id>18</id>

<gradedate>11/27/2006</gradedate>

</grade>

-<grade>

<id>19</id>

<gradedate>11/28/2007</gradedate>

</grade>

-<grade>

<id>20</id>

<gradedate>11/29/2007</gradedate>

</grade>

-<grade>

<id>21</id>

<gradedate>11/30/2007</gradedate>

</grade>

</grades>


Ok, I got it to work but only in IE7, in firefox it get the right amound of nodes but everything comes out as undefined.

using this to get the data

var id = grades[x].childNodes[0].firstChild.text;

var gradedate = grades[x].childNodes[1].firstChild.text;

Also, this is the XML output

<?xml version="1.0" encoding="utf-8"?>

-<grades>

-<grade>

<id>11</id>

<gradedate>11/27/2007</gradedate>

</grade>

- <grade>

<id>18</id>

<gradedate>11/27/2006</gradedate>

</grade>

-<grade>

<id>19</id>

<gradedate>11/28/2007</gradedate>

</grade>

-<grade>

<id>20</id>

<gradedate>11/29/2007</gradedate>

</grade>

-<grade>

<id>21</id>

<gradedate>11/30/2007</gradedate>

</grade>

</grades>


Hi,

Thank you or your post!

I suggest you try this for firefox:

var id = grades[x].childNodes[0].firstChild.nodeValue;

var gradedate = grades[x].childNodes[1].firstChild.nodeValue;

If you have further questions,let me know.

Best Regards,